> 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/deploying-your-own-transactions-server.md).

# 部署你的交易服务器

为用户提供免成本交易

该 [交易服务器](https://github.com/decentraland/transactions-server/tree/1.8.0) 是一个将交易中继至 [Gelato](https://www.gelato.network/relay)的代理服务器。它从客户端接收已签名的交易，然后在后台将其发送到相应的网络。这使服务器所有者能够为其用户提供免成本交易

交易服务器用于改善使用多个网络时的用户体验，并防止用户动态切换网络提供商。用户可以保持连接到 [Ethereum](https://ethereum.org/en/) 并与 [Polygon](https://polygon.technology/) [交互，只需签署交易即可](https://docs.decentraland.org/blockchain-integration/transactions-in-polygon/)

Decentraland DAO 已设置了一台供我们的 dapp 使用的服务器，在一定限额内承担费用，但有一些 [限制](#restrictions)。本文档说明如何 [部署此服务器](#running-the-server) ，以便让你的用户在你所需的限制条件下（如有）中继交易。

## 限制

所有限制均针对用户尝试发送的每笔交易。实际上，这对应于向服务器发送的一个 POST 请求。

服务器可配置的限制包括：

* 检查每日最大交易数量配额。请参阅 [集合部分](#collections) 。
* 检查白名单合约，因此如果交易尝试与未被识别的合约交互，交易将失败。为此，它使用
  * 已部署的合约和集合。请参阅 [合约和集合部分](#contracts-and-collections) 了解更多信息
* 销售价格，如果低于阈值则加以限制。请参阅 [最低销售额部分](#min-sale-value) 了解更多信息

## 配置 Gelato

[Gelato](https://www.gelato.network/relay) 是一个多链中继协议。我们使用其基础设施来实现免成本交易。这实际上意味着，当你要发送交易时，你实际上是在签署一条消息并将其发送给 Gelato。该服务将负责替你发送交易，并向你返回响应（交易哈希）。

它需要一个合约来转发交易，但幸运的是我们可以复用 Decentraland 正在使用的那个合约（见下文）

[Gelato](https://www.gelato.network/relay) 充当服务器的 API。 [要配置](#configuring-the-server) 它，你首先需要一个 API 密钥，我们 [稍后会使用](#gelato)。要获取这些：

* [注册](https://app.gelato.network/relay) 该服务
* 为你打算面向的网络创建新的 dapp。要模拟 Decentraland 的设置：
  * 选择顶部导航栏上的 `主网` 选项
  * 设置一个合适的 `应用名称` 作为你的 dApp 名称
  * 选择 `Polygon` 作为该 `智能合约`
  * 启用 `任意合约` 切换选项
* 从以下位置复制 API 密钥： `API 密钥` 部分

最后，你需要为新创建的 dapp 注资。你可以通过在左侧边栏的 [1Balance](https://app.gelato.network/1balance) 部分连接你的钱包来完成此操作。连接后，你可以存入你的 [USDC](https://polygonscan.com/token/0x3c499c542cef5e3811e1192ce70d8cc03d5c3359) ，为用户将发送的交易提供资金。如果你需要获取 MATIC，请查看这篇 [文章](https://docs.decentraland.org/blockchain-integration/transactions-in-polygon/#where-can-i-get-matic-to-pay-for-transaction-fees).

### 测试网

如果你想在正式上线前测试应用，并且正在使用 Polygon，你可以在 `Polygon Amoy`上进行测试，即 Polygon 测试网。

为此，只需重复 [该过程](#configuring-gelato) ，但在网络字段中选择 `Matic 测试网（Amoy）` 。

你需要为 dapp 注资，但可以从以下位置获取 Sepolia ETH 代币，轻松完成此操作： [水龙头](https://sepoliafaucet.com/).

## 下载交易服务器

首先，你需要一份 Decentraland 交易服务器的代码。你可以在 [GitHub 上](https://github.com/decentraland/transactions-server/tree/v1)找到它。之后，你有两个选项：

1. **下载代码**：要下载代码，你首先必须点击绿色的 `代码` 按钮，然后选择以下任一方式

* 点击 `下载 ZIP`
* 复制以下标题下的 URL，然后运行 `克隆` 代码 `$ git clone THE_URL_HERE`

2. **派生代码**：你可以点击页面右上角的 `派生` 按钮。完成后，你将能够以与第一个选项相同的方式下载你的代码。为此你需要一个 GitHub 账户；有关派生仓库的更多信息，请参阅 [这里](https://docs.github.com/en/enterprise-server@3.5/get-started/quickstart/fork-a-repo)

## 配置服务器

交易服务器使用 [NodeJS](https://nodejs.org/en/) 和 [TypeScript](https://www.typescriptlang.org/)编写。在运行它之前，你需要配置一些环境变量。

操作如下：

* 复制 `.env.defaults` 文件，并将其复制后重命名为 `.env`
* 打开 `.env` 文件。你会看到一些变量具有默认值，例如 `HTTP_SERVER_PORT=5000` （服务器运行所在的端口）
* 大多数值可以保持不变，但有几个重要值需要考虑：
  * [Gelato](#gelato)
  * [交易](#transactions)
  * [合约和集合](#contracts-and-collections)
  * [最低销售额](#min-sale-value)

### Gelato

使用我们在 [配置 Gelato](#configuring-gelato).

```
GELATO_API_KEY=<YOUR_GELATO_API_KEY>
```

### 交易

当新的交易请求到达时，它会检查该数量： **一个地址** 当天已发送的交易数。如果超过设定值，交易将失败。

```
MAX_TRANSACTIONS_PER_DAY=10
```

要完全移除此检查，你可以进入代码并移除

```ts
await checkQuota(components, transactionData)
```

中的方法 `async function checkData(transactionData: TransactionData): Promise<void> {` 在 `src/ports/transaction/component.ts`

### 合约和集合

服务器将获取合约地址 URL，将其存储在本地并查询子图。当新的交易请求到达时，它会检查交易正在交互的合约是否属于该 URL 中已部署的合约，或属于子图中已部署的集合。

如果你想提供自己的合约，请更改 URL，并保持当前 <https://contracts.decentraland.org/addresses.json> 所具有的相同结构。所用网络由 COLLECTIONS\_CHAIN\_ID 确定，重新获取缓存的时间间隔由 COLLECTIONS\_FETCH\_INTERVAL\_MS 确定

如果你有自己的集合，也可以更改子图 URL。

要完全移除此检查，你可以进入代码并移除

```ts
await checkContractAddress(components, transactionData)
```

中的方法 `async function checkData(transactionData: TransactionData): Promise<void> {` 在 `src/ports/transaction/component.ts`

```
CONTRACT_ADDRESSES_URL=https://contracts.decentraland.org/addresses.json
COLLECTIONS_FETCH_INTERVAL_MS=3600000
COLLECTIONS_CHAIN_ID=80002

COLLECTIONS_SUBGRAPH_URL=https://subgraph.decentraland.org/decentraland/collections-matic-amoy
```

### 最低销售额

当新的交易请求到达时，它会首先解析尝试中继的数据。如果检测到销售（市场购买、出价等），它会根据 MIN\_SALE\_VALUE\_IN\_WEI 检查该值。如果该值更低，交易将失败。

```
MIN_SALE_VALUE_IN_WEI=1000000000000000000
```

要查看相关的销售方法，你可以查看 `src/ports/transaction/validation/checkSalePrice.ts` 要完全移除此检查，你可以进入代码并移除

```ts
await checkSalePrice(components, transactionData)
```

中的方法 `async function checkData(transactionData: TransactionData): Promise<void> {` 在 `src/ports/transaction/component.ts`

## 运行服务器

现在所有配置均已完成，剩下的就是实际运行服务器。你可以按照 [其 README](/creator/content-creator-zh/chang-jing-sdk7/qu-kuai-lian/deploying-your-own-transactions-server.md) 操作，但简而言之，你需要：

* 安装 [NodeJS](https://nodejs.org/en/) 完成
* 打开你选择的终端
* 运行以下命令：

```bash
npm install
npm run migrate # 仅首次运行
npm run start
```

当然，你可能希望将它部署到你选择的服务上，例如 [AWS](https://aws.amazon.com/) 。你可以使用项目的 [Dockerfile](https://github.com/decentraland/transactions-server/blob/master/Dockerfile) 来完成此操作。

## 使用服务器

现在一切都已设置并运行，是时候实际使用服务器了。

要实际发送交易，你需要向 `/transactions`发送 POST 请求。该请求所需的 schema 由以下内容定义： `transactionSchema` 位于 `src/ports/transaction/types.ts`.

或者，如果你想使用我们预先制作的库来让操作更轻松，可以尝试 [decentraland-transactions](https://github.com/decentraland/decentraland-transactions)。它通过 [decentraland-dapps](https://github.com/decentraland/decentraland-dapps) 在我们的 dapp 中使用，例如 [市场](https://market.decentraland.org)，配合工具函数 [`sendTransaction`](https://github.com/decentraland/decentraland-dapps/blob/master/src/modules/wallet/utils.ts#L104)。查看 [这段代码](https://github.com/decentraland/marketplace/blob/a2191515c6ae7ede54a685cc2dd9f9fafa35366b/webapp/src/modules/vendor/decentraland/OrderService.ts#L33) 以获取示例。


---

# 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/deploying-your-own-transactions-server.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.
