> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/qu-kuai-lian/second-layer.md).

# 第二层

在你的场景中使用 Polygon 的侧链，以实现更快、更便宜的区块链交易。

## 关于第二层解决方案

任何会影响区块链的交易都需要时间完成，并且会消耗 gas。这两者都是让区块链游戏普及的障碍，因为玩家通常没有耐心等待那么久让他们的操作生效，也不愿意在游戏过程中为多笔交易花钱。

一种常见的变通方法是将大部分游戏过程放在链下，只在关键事件上执行区块链交易，例如赚取游戏物品或登记高分。

然而，另一种克服这些限制以及区块链固有的其他可扩展性问题的方法，是依赖于一个 *第二层* 区块链，也称为一个 *侧链*.

第二层是另一条区块链，充当去中心化应用与主链之间的中介。该层更轻量，因此能够以更低的 gas 成本提供更快的响应。

交易不会直接写入主链，而是在侧链上完成，然后由侧链负责最终将这些变更与主链同步。

侧链之所以能够提供更快的响应，是因为它是一个节点更少、更小的网络。在第二层执行的交易起初安全性较低，但它们最终会批量提交到主链，而主链的所有安全检查都可以在那里执行。

侧链还能够显著降低单笔交易成本，因为它在与主链同步时会将许多交易合并为一笔。因此，原本在主链上一笔交易需要支付的 gas，可以分摊到数千笔交易上。

此外，在与主链同步时，还可以完全避免若干冗余交易，从而进一步降低交易成本。例如，如果 Alice 向 Bob 转账 1 ETH，然后 Bob 再向 Carol 转账 1 ETH，那么这两笔交易可以简化为一笔，只需记录 Alice 直接向 Carol 转账即可。

Decentraland 与 [Polygon](https://polygon.technology/)有合作关系，他们在以太坊上提供自己的侧链。场景可以使用他们的侧链来支持快速且非常便宜的交易。

## 试用 Polygon 测试网

要使用 Polygon 的 Matic 测试网，你首先需要拥有：

* Sepolia 网络中的 Ether。你可以从各种外部水龙头免费获取，例如 [这个](https://www.alchemy.com/faucets/ethereum-sepolia).

然后你必须配置你的 Metamask 账户，以添加 Matic 测试网。

为此：

1. 在 Metamask 中切换网络，点击当前网络名称并选择 *自定义 RPC* 在下拉菜单底部。
2. 将“Polygon Amoy Testnet”填写为 *网络名称*, [**https://rpc-amoy.polygon.technology**](https://rpc-amoy.polygon.technology) 作为 *新 RPC URL* 和 [**https://amoy.polygonscan.com**](https://amoy.polygonscan.com) 作为 *区块浏览器 URL*。对于 *符号* 设置为 **POL**
3. 点击“保存”将此新网络添加到 Metamask。

{% hint style="warning" %}
**📔 注意**：了解如何在他们的 [文档页面上设置 Polygon 的更多信息](https://docs.polygon.technology/)
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/qu-kuai-lian/second-layer.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
