> 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 在 Ethereum 上提供自己的侧链。场景可以使用这条侧链来支持快速且成本极低的交易。

## 试用 Polygon 测试网

要使用 Polygon 的 Matic 测试网，你需要先准备：

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

然后，你必须配置 Metamask 账户，将 Matic 测试网添加进去。

操作步骤如下：

1. 点击 Metamask 中当前网络的名称并选择 *自定义 RPC* （位于下拉菜单底部），切换网络。
2. 在「网络名称」中填写「Polygon Amoy 测试网」 *网络名称*, [**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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
