---
title: "Solana RPC 端点文档 - ERPC"
description: "了解如何使用 ERPC 获取 Solana RPC 端点、配置 API key，并通过 HTTP 或 WebSocket 访问 Solana 端点。"
canonical: "https://erpc.global/zh/doc/rpc/general/"
locale: "zh"
---

# Solana RPC 端点文档 - ERPC

## Solana RPC 端点文档

Solana RPC 端点是应用连接 Solana 网络的 API 地址。使用 ERPC 时，您可以用同一个 API key 通过 HTTP 发送 JSON-RPC 请求，或通过 WebSocket 订阅实时更新。

请将您的 API key 添加到 `api-key` 参数中。

```text
https://edge.erpc.global?api-key=<YOUR_API_KEY>
```

### 示例：

以下示例会通过 Solana RPC 端点调用 `getBlockHeight`。

```bash
curl https://edge.erpc.global?api-key=<YOUR_API_KEY> --header 'Content-Type: application/json' --data '{
  "jsonrpc":"2.0","id":1,
  "method":"getBlockHeight"
}'
```

以下是 WebSocket 订阅示例。主机地址与 HTTP 相同。

```text
wss://edge.erpc.global?api-key=<YOUR_API_KEY>
```

```bash
# 示例：订阅 slot 更新
wscat -c "wss://edge.erpc.global?api-key=<YOUR_API_KEY>"
# 连接后发送：
{"jsonrpc":"2.0","id":1,"method":"slotSubscribe"}
```

您可以在 [ERPC Dashboard](https://dashboard.erpc.global/zh) 获取和查看 API key。

如果您需要比 WebSocket 更低的延迟，请考虑使用 Geyser gRPC 或 ShredStream。您可以在 ERPC Dashboard 中与我们讨论适合的 Solana 端点配置。

### History Access

要查找较早的区块和交易，请在 HTTP 请求的 `edge.erpc.global` URL 中加入 `history=true`；值必须恰好是小写的 `true`。除 `getTransactionsForAddress` 外，不带 `history=true` 的请求由每个节点保存的近期范围响应；该选项适用于以下方法：

- `getBlock`
- `getBlockTime`
- `getBlocks`
- `getBlocksWithLimit`
- `getTransaction`，包括 `getParsedTransaction`
- `getSignaturesForAddress`
- `getSignatureStatuses`，当 `searchTransactionHistory` 为 `true` 时
- `getTransactionsForAddress`，当 `transactionDetails` 为 `"full"` 时（需要 History Access）

将 API key 和该选项作为 query parameter 放在 URL 中：

```text
https://edge.erpc.global?api-key=<YOUR_API_KEY>&history=true
```

或者将 `Authorization: Bearer <YOUR_API_KEY>` 作为 header 发送，并在 URL 中保留该选项：

```text
https://edge.erpc.global?history=true
```

以下是使用 History Access 的 HTTP 请求示例。

```bash
curl 'https://edge.erpc.global?history=true' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc":"2.0","id":1,
  "method":"getBlock",
  "params":[<SLOT>,{"maxSupportedTransactionVersion":1}]
}'
```

对于除 `getTransactionsForAddress` 的 `"full"` 模式之外的所有方法：

- 每个由 History Access 响应的调用比其常规价格多消耗 640 个代币：`getBlock` 消耗 42 + 640 = 682。
- 来自 History Access 的 `null`、空结果或部分结果同样产生额外消耗。查找失败不产生额外消耗。
- 由近期数据响应的调用即使带有 `history=true`，也保持常规价格。
- 批次会逐个计算其中的每次调用；`getSignatureStatuses` 每次调用只计算一次，而不是按签名计算。
- 轮询近期交易时请不要加 `history=true`：那里的每个 `null` 都会产生额外消耗。

免费额度（包括 Free 方案的额度）对 History Access 设有上限。Free 方案限制为每 10 秒一个 History Access 请求。

`transactionDetails` 设为 `"full"` 的 `getTransactionsForAddress` 调用属于 History Access，无论交易是近期的还是较早的：

- 该调用要求在 `edge.erpc.global` URL 中带上 `history=true`。不带此选项的请求会被拒绝并返回 History Access 错误（错误码 `-32011`），且不产生任何消耗。
- 带有 `history=true` 时，该调用消耗 420 + 640 × N 个代币：其常规价格 420，加上所获取的 N 笔交易每笔 640，无论交易是近期的还是较早的。没有交易的记录不计入。
- 该调用必须作为单独的请求发送。包含它的批次无论是否带有 `history=true` 都会被拒绝：批次中的每个调用都会收到错误 `-32600` 和消息 `This request is not available in a mixed JSON-RPC batch. Please send it as a separate request.`，且其中没有任何一个会被发送。

默认的 `signatures` 模式不需要 `history=true`，也不产生额外消耗。如需轮询某个地址的新交易，请使用 `signatures` 模式，并通过 `getTransaction` 获取所需的交易。

查找较早的区块或交易可能比普通请求耗时长得多，某些情况下会达到数秒。History Access 是一个独立的选项，它把这类查找与普通请求分开，从而让普通请求保持快速。

不带 `history=true` 时，对较早 slot 发出的 `getBlock` 或 `getBlockTime` 请求可能返回以下错误：

```json
{
  "jsonrpc": "2.0",
  "error": {
    "code": -32011,
    "message": "This request needs history access. Add history=true to the endpoint URL.",
    "data": {
      "erpcCode": "ERPC_HISTORY_OPTION_REQUIRED"
    }
  },
  "id": 1
}
```

对于早于节点所保存范围的签名，`getTransaction`、`getParsedTransaction` 和 `getSignatureStatuses`（`searchTransactionHistory: true` 时）返回 `null`，而 `getSignaturesForAddress`、`getBlocks` 和 `getBlocksWithLimit` 返回空结果或部分结果。

带有 `history=true` 的请求可能返回以下消息：

- `This plan has reached its limit for history access. Add a paid plan to use tokens for history access.` — 当某项免费额度（例如 Free 方案的额度）达到上限时显示。
- `History access is unavailable while your token balance is low. Add tokens.` — 在付费方案中，代币余额不足时显示。
- `On the Free plan, history access is limited to one request per 10 seconds. Slow down or use a paid plan.` — 在 Free 方案中，History Access 请求到达过快时显示。

### Unlimited Endpoint 支持方法

Unlimited Endpoints 是为低延迟标准 Solana RPC 调用优化的专用 HTTP 端点。支持的标准 Solana RPC 方法为：

- `getSlot`
- `getBlockHeight`
- `getLatestBlockhash`
- `getBalance`
- `getAccountInfo`
- `getMultipleAccounts`
- `getTransaction`
- `sendTransaction`
- `simulateTransaction`
- `getSignatureStatuses`
- `getRecentPrioritizationFees`
- `getHealth`
- `getVersion`
- `getEpochInfo`
- `getBlock`

对于不在此支持范围内的方法，请使用 `https://edge.erpc.global?api-key=<YOUR_API_KEY>`。

### Solana RPC 方法和文档

有关方法、参数和订阅规范的完整列表，请参阅官方文档。文档涵盖 HTTP 和 WebSocket 的使用方式。

[https://solana.com/docs/rpc](https://solana.com/docs/rpc)
