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

# 历史与事件

> /v1 下的地址和合约历史、TRC-20 转账，以及交易和区块事件

## 这是什么

Node API 在与节点方法相同的主机上、使用相同的密钥，提供通用 TRON `/v1` 格式中的历史与事件路径。为该格式编写的客户端，只需更换主机和密钥即可使用。

| 路径 | 返回内容 |
| - | - |
| `GET /v1/accounts/{address}/transactions/trc20` | 某个地址转出和转入的 TRC-20 转账 |
| `GET /v1/accounts/{address}/transactions` | 某个地址的交易：它发出的和发给它的 |
| `GET /v1/contracts/{address}/transactions` | 发给某个合约的交易——即对它的调用 |
| `GET /v1/transactions/{id}/events` | 某笔交易的事件（日志） |
| `GET /v1/blocks/{number}/events` | 某个区块的事件 |
| `GET /v1/blocks/latest/events` | 最新区块的事件 |

* 仅支持 `GET`；其他 HTTP 方法会得到 `405 method_not_allowed`。
* `{address}` 可以是 base58（`T…`）或 hex（`41…`、`0x41…`）。
* 与所有方法一样，密钥放在 `TRON-PRO-API-KEY` 请求头或路径中：
  `https://node.tronrental.com/<YOUR_KEY>/v1/accounts/{address}/transactions`。
* 其他 `/v1/...` 路径——例如 `/v1/accounts/{address}` 或 `/v1/contracts/{address}/events`——不提供，会得到 `404 not_found`。
* `GET /healthcheck` 无需密钥即返回 `200 {"ok": true}`：TronWeb 的 `isConnected()` 会调用它。

```bash theme={null}
curl -s 'https://node.tronrental.com/v1/accounts/TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t/transactions/trc20?limit=20&only_to=true' \
  -H 'TRON-PRO-API-KEY: <YOUR_KEY>' --compressed
```

## 可追溯范围

| 数据 | 起始时间 |
| - | - |
| 地址的转出交易和转出 TRC-20 转账 | 网络创世 |
| 地址的转入交易、合约的调用 | 2026-05-01 00:00 UTC |
| 地址的转入 TRC-20 转账 | 2026-06-01 00:00 UTC |
| 包含带内部交易的合约调用的 `…/transactions` 页面 | 2026-10-08 07:32:42 UTC（区块 86,924,000） |
| 交易或区块的事件 | 任意区块 |

晚于各日期的历史照常提供；该日期之后的最后一页仍带有 `fingerprint`，而要读取到该日期之前的调用会得到 `400`，并说明应传入什么：

```json theme={null}
{
  "success": false,
  "error": "incoming transfers before 2026-06-01 are not available yet: pass only_from=true, or min_timestamp >= 1780272000000",
  "statusCode": 400
}
```

* 使用 `only_from=true` 时，地址的转出方向可一直读取到网络创世。
* 2026-10-08 之前、可能继续转出 TRX 或代币（内部交易）的合约调用会被拒绝，而不是在缺少内部交易的情况下返回。对 USDT 合约的调用始终可以返回：它不调用其他合约。

## 参数

历史——三个 `…/transactions` 路径：

| 参数 | 含义 |
| - | - |
| `limit` | 每页条数，1–200。默认 20 |
| `fingerprint` | 下一页的起点：上一页的 `meta.fingerprint` |
| `order_by` | `block_timestamp,desc`（默认，最新的在前）或 `block_timestamp,asc` |
| `min_timestamp`、`max_timestamp` | 以毫秒为单位的边界。`0` 表示无边界 |
| `only_confirmed`、`only_unconfirmed` | `true`——仅已固化的区块，或仅其之上的区块。二者不可同时使用 |
| `only_to`、`only_from` | 仅限账户：仅转入，或仅转出 |
| `contract_address` | 仅限 TRC-20 历史：只看一种代币的转账 |

`search_internal` 可以传入，但不起作用。合约的 `…/transactions` 只有一个方向——发给它的交易——因此 `only_to` 和 `only_from` 在那里不适用。

事件：`limit`（1–200，默认 20）、`fingerprint`、`only_confirmed` 或 `only_unconfirmed`。

## 分页

后面还有数据的页面带有 `meta.fingerprint` 和 `meta.links.next`——即带有新 `fingerprint` 的同一 URL（如果您把密钥放在路径中，也包含密钥）。最后一页两者都没有。

一次历史调用只读取索引的有限部分。因此，一页返回的条数可能少于 `limit`，甚至为空，但仍带有 `next`。请持续跟随 `next`，直到它消失；带有 `next` 的空页并不是结尾。

```python theme={null}
import requests

URL = "https://node.tronrental.com/v1/accounts/{}/transactions/trc20"
HEADERS = {"TRON-PRO-API-KEY": "<YOUR_KEY>"}

def incoming_usdt(address, since_ms):
    url = URL.format(address)
    params = {"only_to": "true", "min_timestamp": since_ms, "limit": 200,
              "contract_address": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"}
    while url:
        page = requests.get(url, params=params, headers=HEADERS).json()
        yield from page["data"]
        url, params = page.get("meta", {}).get("links", {}).get("next"), None
```

## 响应

### TRC-20 转账

```json theme={null}
{
  "data": [
    {
      "transaction_id": "8f0c…",
      "token_info": {
        "symbol": "USDT",
        "address": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
        "decimals": 6,
        "name": "Tether USD"
      },
      "block_timestamp": 1796149026000,
      "from": "TXa…",
      "to": "TQb…",
      "type": "Transfer",
      "value": "1500000"
    }
  ],
  "success": true,
  "meta": {
    "at": 1796282340623,
    "page_size": 1,
    "fingerprint": "…",
    "links": { "next": "https://node.tronrental.com/v1/accounts/…/transactions/trc20?fingerprint=…" }
  }
}
```

* 仅包含 `Transfer` 事件；`Approval` 不在此历史中。
* `value` 是以代币最小单位表示的字符串；除以 `10^decimals`。
* `block_timestamp` 和 `meta.at` 以毫秒为单位。地址为 base58。

### 交易

每一项都是节点所存储的交易本身——`txID`、`raw_data`、`raw_data_hex`、`signature`、`ret`——再加上其回执中的字段：`blockNumber`、`block_timestamp`（毫秒）、`net_usage`、`net_fee`、`energy_usage`、`energy_fee`、`energy_usage_total`、`internal_transactions`，以及 `ret[0].fee` 中的手续费。`raw_data` 中的地址为 hex，与节点给出的一致。

* 失败的交易（`REVERT`、`OUT_OF_ENERGY`）也包含在内。
* 在 `/v1/contracts/{address}/transactions` 中，`blockNumber` 和 `block_timestamp` 是字符串，`ret[0]` 中没有 `fee`，这正是该格式的客户端所预期的。
* 内部交易：`internal_tx_id`、`from_address`、`to_address`，以及包含 `note`、`rejected` 和 `call_value` 的 `data`（TRX 位于 `_` 下，TRC-10 代币位于其 id 下；仅在有价值转移时出现）。

### 事件

```json theme={null}
{
  "block_number": 78000000,
  "block_timestamp": 1764000000000,
  "caller_contract_address": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
  "contract_address": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
  "event_index": 0,
  "event_name": "Transfer",
  "event": "Transfer(address indexed from, address indexed to, uint256 value)",
  "result": { "0": "0x…", "1": "0x…", "2": "1500000", "from": "0x…", "to": "0x…", "value": "1500000" },
  "result_type": { "from": "address", "to": "address", "value": "uint256" },
  "transaction_id": "8f0c…"
}
```

* 最新的在前：区块中的最后一笔交易，以及该交易中的最后一条日志。
* `_unconfirmed: true` 标记位于已固化链头之上的事件。
* 未知的交易、没有事件的区块，或尚未产生的区块：返回 `200`，`data` 为空。
* 日志使用链上合约的 ABI 解码。对于没有 ABI 的合约，常见事件（`Transfer`、`Approval`、`Swap`、`Sync` 等）按标准签名解码；无法识别名称的日志带有 `event_name: ""` 和空的 `result`。

使用 TronWeb 时，只需设置 `fullHost` 和密钥：它的事件方法会在同一主机上调用这些路径。

```javascript theme={null}
const { TronWeb } = require('tronweb');

const tronWeb = new TronWeb({
  fullHost: 'https://node.tronrental.com',
  headers: { 'TRON-PRO-API-KEY': '<YOUR_KEY>' },
});

const events = await tronWeb.event.getEventsByTransactionID(txId);
```

## 费用与限制

| 调用 | WU | 每秒限制 |
| - | - | - |
| TRC-20 历史 | 每读取 100 MB 索引 1 WU，且不低于按响应大小计算的值——通常为几 WU，最多 20 | 读取（WU/s） |
| 地址或合约的交易 | 索引读取费用，再加上每笔交易调用 `gettransactionbyid` 和 `gettransactioninfobyid` 所需的费用——20 条一页约 40 WU 起 | 读取（WU/s） |
| 交易的事件 | 与 `gettransactioninfobyid` 相同——按回执大小 | 读取（WU/s） |
| 区块的事件 | 与 `gettransactioninfobyblocknum` 相同：新区块（距链头 20 个以内）2 WU，较旧的按大小 | 区块 |

`X-Node-API-WU` 响应头会告诉您每次调用的费用。因参数错误返回的 `400` 最多消耗 1 WU。参见[配额单位](https://docs.tronrental.com/zh/node-api/quota-units.md)。

## 错误

| 状态 | 响应体或 `code` | 含义 | 处理方式 |
| - | - | - | - |
| `400` | `{"success": false, "error": "…", "statusCode": 400}` | 参数错误、来自其他查询的 `fingerprint`，或历史尚未覆盖到的日期 | 阅读 `error` 并修正请求 |
| `503` | `index_unavailable` | 索引繁忙、正在追赶链，或该地址过于活跃，无法在一次调用中处理（缩小 `min_timestamp`/`max_timestamp`） | 几秒后重试 |
| `503` | `node_behind` | 交易：节点尚未同步到该页中的某个区块 | 重试 |
| `503` | `degraded` | 降级模式下不提供旧区块的历史和事件 | 稍后重试 |
| `502` | `node_error` | 构建页面时节点没有响应 | 重试 |

其他所有拒绝——密钥、套餐、限制——与节点方法相同：参见[限制与错误](https://docs.tronrental.com/zh/node-api/errors.md)。


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