> ## Documentation Index
> Fetch the complete documentation index at: https://docs.li.fi/llms.txt
> Use this file to discover all available pages before exploring further.

# Tron 提供方

> Tron Architecture

LI.FI 提供 Tron 与其他受支持生态系统（例如 EVM 链和 Solana）之间的桥接。

> [!NOTE]
>
> LI.FI 中 Tron 的 chainId 为 `728126428`（链密钥 `TRN`）。
>
> 原生 TRX 表示为 `T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb`（6 位小数）。TRC20 代币通过其 Base58 合约地址（`T...`）寻址。
>
> Tron 地址为 Base58 格式且区分大小写。请始终按照 API 返回的原样传递地址。不接受十六进制形式（`41...`）。

> [!NOTE]
>
> Tron 上的同链交换目前尚不支持。以 Tron 作为源链的报价始终为跨链报价。

## 请求报价

Tron 的报价可以使用与 EVM 相同的接口请求，仅链 ID、代币地址和交易数据有所不同。

> [!NOTE]
>
> 当源链为 Tron 时，`fromAddress` 必须是 Base58 格式的 `T...` 账户地址。
>
> 当 Tron 为目标链时，`toAddress` 是 Base58 格式的 `T...` 地址。从 Tron 桥接到其他链时，`toAddress` 是目标链上的常规地址（例如 EVM 地址）。

## 代币授权

发送 TRC20 代币需要代币授权：执行合约会从您的账户中提取代币，因此在执行前，请为该步骤的 `estimate.approvalAddress` 授予至少 `fromAmount` 的额度。原生 TRX 作为交易的调用值传递，无需授权。

要检查某条路由是否需要授权，请扫描报价中的 `includedSteps`：只要某个步骤的 `estimate.skipApproval` 不为 `true`，就需要为该步骤的 `estimate.approvalAddress` 进行授权。

> [!NOTE]
>
> 授权是一笔单独的 Tron 交易（TRC20 的 `approve(spender, amount)`）。请提交该交易并等待其确认后，再广播 LI.FI 交易。

## 执行交易

### 交易数据

`transactionRequest` 以两种形式携带未签名的 Tron 交易：

* `data` —— 未签名的 `TriggerSmartContract` 交易经十六进制编码的 protobuf `raw_data`（即 Tron 节点的 `raw_data_hex`），并以 `0x` 为前缀。
* `customData.tronTransaction` —— 同一笔交易的 TronWeb 交易对象形式：`{ visible, txID, raw_data, raw_data_hex }`。`customData.contractType` 为 `TriggerSmartContract`。

该对象内部的 `raw_data_hex` 和 `txID` 均为不带 `0x` 前缀的小写十六进制字符串，因此 `data` 等于 `0x` + `raw_data_hex`。

`to` 是 Tron 上的 LI.FI 合约，`value` 是以 SUN 为单位的 TRX 调用值，`gasLimit` 是该交易以 SUN 为单位的 `fee_limit`（参见 [Gas](#gas)）。两者均为十六进制编码的字符串，与交易对象中的 `raw_data.fee_limit` 一致。

使用 [TronWeb](https://tronweb.network/) 执行交易：

1. 通过常规报价流程请求交易数据。
2. 使用发送方账户的私钥对 `customData.tronTransaction` 进行签名。
3. 将签名后的交易广播到 Tron 网络。

```typescript theme={"system"}
import { TronWeb } from "tronweb";

const tronWeb = new TronWeb({
  fullHost: "https://api.trongrid.io",
  privateKey: SENDER_PRIVATE_KEY,
});

const { transactionRequest } = quote;
const transaction = transactionRequest.customData.tronTransaction;

const signedTransaction = await tronWeb.trx.sign(transaction);
const { result, txid } = await tronWeb.trx.sendRawTransaction(signedTransaction);
```

> [!NOTE]
>
> 仅凭 `data` 即可在不使用 TronWeb 的情况下重建交易：交易 ID 是 `raw_data` 字节的 SHA-256 哈希（请先去掉 `0x` 前缀），签名即针对该 ID 生成。使用 `customData.tronTransaction` 可以省去反序列化的步骤。

> [!WARNING]
>
> **交易有效期**
>
> 该交易在 `raw_data.expiration`（构建后约 10 分钟）之前均有效。网络会拒绝在过期后广播的交易。
>
> * 收到交易数据后应尽快签名并广播。
> * 如果手中的交易已过期，请重新请求一笔新的交易。
> * 如果签名耗时较长（例如使用 MPC 签名方），请在签名**之前**延长过期时间。TronWeb 会为您重新计算 `txID` 和 `raw_data_hex`：
>
> ```typescript theme={"system"}
> const extendedTransaction = await tronWeb.transactionBuilder.extendExpiration(
>   transaction,
>   extraSeconds
> );
> const signedTransaction = await tronWeb.trx.sign(extendedTransaction);
> ```
>
> 过期时间距当前区块不能超过 24 小时。请勿修改 `raw_data` 的任何其他字段。

### Gas

Tron 收取带宽（bandwidth）和能量（energy）费用。预估费用会在该步骤的 `estimate.gasCosts` 中以两条 `SEND` 记录返回，单位为 SUN（TRX，6 位小数）：一条对应带宽，一条对应能量。系统会优先消耗发送方账户质押的资源，不足部分以 TRX 燃烧结算。

`transactionRequest.gasLimit` 是该交易的 `fee_limit`：即该交易允许为能量燃烧的最大 TRX 数量。这是一个安全上限，并非预期费用。

## 状态跟踪

交易状态可以通过常规的[状态跟踪](https://docs.li.fi/introduction/user-flows-and-examples/status-tracking.md)流程进行跟踪。

> [!NOTE]
>
> 在轮询源自 Tron 的交易的 `/status` 时，请始终传递 `fromChain=TRN`（或 Tron 链 ID `728126428`）。Tron 交易哈希为 64 位十六进制字符串，否则将与 Bitcoin 交易哈希无法区分。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.