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

# getHistoricalAccountInfo

> 读取任意 Solana 账户在过去某个槽位或特定交易刚执行后的状态，支持 getAccountInfo 编码，并返回最后一次写入的位置。

> [!NOTE]
>
> `getHistoricalAccountInfo` 处于 Beta 阶段。参数、定价、响应格式和数据覆盖范围可能会发生变化。

## 概述

`getHistoricalAccountInfo` 返回 Solana 账户在过去某个槽位或该槽位中特定交易刚执行后的状态。这是 Helius 独有的 RPC 方法。标准的 `getAccountInfo` 仅返回当前状态。

响应包含与 `getAccountInfo` 相同的账户字段，并额外包含 `lastUpdatedAt`：最后一次写入所返回状态的槽位和交易。

历史数据从槽位 444,959,999（2026 年 9 月 7 日）起可用，即纪元 1030 开始时的状态。请求更早的槽位会返回错误 `-32018`。

`getHistoricalAccountInfo` 在主网上面向 Business 及更高级别的套餐提供，Beta 期间每次调用消耗 0 个积分。定价可能会发生变化。

## 选择历史位置

第二个参数是一个查询对象，用于选择要读取的历史时间点：

| 查询 | 返回的账户状态 |
| - | - |
| 省略或 `{}` | 最新已索引槽位的状态，上限为所请求的确认级别 |
| `{ "slot": 445000000 }` | 槽位 445,000,000 结束时的状态 |
| `{ "slot": 445000000, "transactionIndex": 10 }` | 槽位 445,000,000 中索引为 10 的交易刚执行后的状态 |

`transactionIndex` 要求提供 `slot`。要读取索引为 `N` 的交易执行前的账户状态，请查询 `transactionIndex: N - 1`。对于槽位中的第一笔交易，请查询前一个槽位，并且不要提供 `transactionIndex`。

纪元奖励等非交易写入会在槽位结束时应用。包含 `transactionIndex` 的查询绝不会包含这些写入。

## 请求示例

```bash theme={"system"}
curl https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": "1",
    "method": "getHistoricalAccountInfo",
    "params": [
      "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
      { "slot": 445000000 },
      { "encoding": "jsonParsed" }
    ]
  }'
```

## 解读响应

* **`value`** 是账户在所请求位置的状态；如果账户当时不存在，则为 `null`：账户尚未创建或已关闭。值为 `null` 的响应不包含 `lastUpdatedAt`。
* **`lastUpdatedAt.slot`** 和 **`lastUpdatedAt.transactionIndex`** 标识产生此状态的写入。该写入发生在你请求的位置或之前。
* 当写入发生在交易之外（例如纪元奖励）时，**`lastUpdatedAt.transactionIndex` 为 `null`**。
* **`lastUpdatedAt.slot` 为 444,959,999 且 `transactionIndex` 为 `null`**，表示自历史数据覆盖开始以来，该账户未发生变化。这并不表示账户是在该槽位写入的。
* **`context.slot`** 是 Helius 处理请求时已索引的最新槽位，而不是你查询的槽位。
* **`jsonParsed` 代币账户**使用铸币在所请求位置的小数位数。如果无法读取该位置的铸币，账户将回退到 base64。

要列出账户过去的每个状态，请使用 `lastUpdatedAt` 作为游标。请参阅[回溯账户历史记录](https://www.helius.dev/docs/zh/rpc/historical-accounts.md#向前回溯账户历史记录)。

## 错误

| 代码 | 含义 |
| - | - |
| `-32018` | 该槽位早于历史数据覆盖的起点（槽位 444,959,999） |
| `-32004` | 该槽位比所请求的确认级别允许的槽位更新。请使用 `confirmed` 或查询更早的槽位 |
| `-32602` | 参数无效，例如提供 `transactionIndex` 但未提供 `slot`、使用 `base58` 编码，或包含未知的配置字段 |
| `-32601` | 找不到方法。请调用你的 Helius 主网或 Gatekeeper 端点；该方法在开发网上不可用 |

## 相关方法

> [card] [Historical Accounts Guide](https://www.helius.dev/docs/zh/rpc/historical-accounts.md)
>
> 了解历史账户方法的位置、覆盖范围和 lastUpdatedAt 的工作原理

> [card] [getHistoricalTokenAccountsByOwner](https://www.helius.dev/docs/zh/api-reference/rpc/http/gethistoricaltokenaccountsbyowner.md)
>
> 列出钱包在过去某个槽位的代币账户

> [card] [getTransactionsForAddress](https://www.helius.dev/docs/zh/rpc/gettransactionsforaddress.md)
>
> 查找你要检查的交易对应的槽位和 transactionIndex

> [card] [getAccountInfo](https://www.helius.dev/docs/zh/api-reference/rpc/http/getaccountinfo.md)
>
> 读取账户的当前状态

## 请求参数

**pubkey** `string` *required*

要读取的账户地址，使用 Base-58 编码。

**slot** `number`

要读取状态的槽位。返回该槽位结束时的账户状态。最早支持的槽位是 444959999，即纪元 1030 开始时的状态。省略时，将读取最新已索引的槽位，上限为所请求的确认级别。

**transactionIndex** `number`

交易在槽位中的位置。返回该交易刚执行后的账户状态，而不是槽位结束时的状态。必须提供 slot。

**encoding** `string` (default: base64)

账户数据的编码格式。不支持 base58 和 binary。

* `base64`
* `base64+zstd`
* `jsonParsed`

**dataSlice** `object`

仅返回每个账户数据的一个切片。适用于 base64 和 base64+zstd 编码。

**dataSlice.offset** `number` *required*

开始读取位置的字节偏移量。

**dataSlice.length** `number` *required*

要返回的字节数。

**commitment** `string` (default: finalized)

确认级别。不支持 processed。

* `finalized`
* `confirmed`

**minContextSlot** `number`

可评估该请求的最小槽位。


## OpenAPI

````yaml zh/openapi/rpc-http/getHistoricalAccountInfo.yaml POST /
openapi: 3.1.0
info:
  title: Solana RPC API
  version: 1.0.0
  description: 历史 Solana 账户状态 API，用于读取任意账户在过去某个时隙时的状态，或该时隙内某笔特定交易完成后的即时状态。
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
  - url: https://mainnet.helius-rpc.com
    description: 主网 RPC 端点
security: []
paths:
  /:
    post:
      tags:
        - RPC
      summary: getHistoricalAccountInfo
      description: |
        **测试版。** 参数、响应格式和数据覆盖范围可能会发生变化。

        返回 Solana 账户在过去某个时隙时的状态，或该时隙内某笔特定
        交易完成后的即时状态。此 Helius RPC 方法接受与 getAccountInfo 相同的地址和
        编码选项，此外还接受一个查询对象，用于选择要读取的
        历史位置。

        历史记录覆盖时隙 444959999（纪元 1030 的起点）及之后的时隙。每个返回的账户
        都包含 lastUpdatedAt，即最后一次写入你所收到状态的时隙和交易。
      operationId: getHistoricalAccountInfo
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - jsonrpc
                - id
                - method
                - params
              properties:
                jsonrpc:
                  type: string
                  enum:
                    - '2.0'
                  example: '2.0'
                  description: JSON-RPC 协议版本。
                  default: '2.0'
                id:
                  type: string
                  example: '1'
                  description: 请求的唯一标识符。
                  default: '1'
                method:
                  type: string
                  enum:
                    - getHistoricalAccountInfo
                  example: getHistoricalAccountInfo
                  description: 要调用的 RPC 方法名称。
                  default: getHistoricalAccountInfo
                params:
                  type: array
                  description: 包含账户地址、用于选择历史位置的可选查询对象，以及可选配置对象的数组。
                  minItems: 1
                  maxItems: 3
                  default:
                    - EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
                    - slot: 445000000
                    - encoding: jsonParsed
                  items:
                    oneOf:
                      - type: string
                        title: 公钥
                        description: 要读取的账户的 Base-58 编码地址。
                        example: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
                      - $ref: '#/components/schemas/HistoricalAccountQuery'
                        title: 查询
                      - type: object
                        title: 配置
                        description: 可选配置对象。
                        properties:
                          encoding:
                            type: string
                            description: 账户数据的编码格式。不支持 base58 和 binary。
                            enum:
                              - base64
                              - base64+zstd
                              - jsonParsed
                            default: base64
                            example: jsonParsed
                          dataSlice:
                            $ref: '#/components/schemas/DataSliceConfig'
                          commitment:
                            type: string
                            description: 承诺级别。不支持 processed。
                            enum:
                              - finalized
                              - confirmed
                            default: finalized
                            example: finalized
                          minContextSlot:
                            type: integer
                            description: 可评估请求的最小时隙。
                            example: 445000000
                        additionalProperties: false
      responses:
        '200':
          description: 已成功检索历史账户状态。
          content:
            application/json:
              schema:
                type: object
                properties:
                  jsonrpc:
                    type: string
                    description: JSON-RPC 协议版本。
                    enum:
                      - '2.0'
                    example: '2.0'
                  id:
                    type: string
                    description: 与请求匹配的标识符。
                    example: '1'
                  result:
                    type: object
                    properties:
                      context:
                        $ref: '#/components/schemas/HistoricalContext'
                      value:
                        oneOf:
                          - $ref: '#/components/schemas/HistoricalAccount'
                          - type: 'null'
                        description: 账户在请求位置时的状态；如果当时不存在，则为 null。
        '400':
          description: 错误请求 - 请求参数无效或请求格式错误。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                jsonrpc: '2.0'
                error:
                  code: -32602
                  message: 参数无效
                id: '1'
        '401':
          description: 未授权 - API 密钥无效或缺失。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                jsonrpc: '2.0'
                error:
                  code: -32001
                  message: 未授权
                id: '1'
        '429':
          description: 请求过多 - 已超出速率限制。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                jsonrpc: '2.0'
                error:
                  code: -32005
                  message: 请求过多
                id: '1'
        '500':
          description: 内部服务器错误 - 服务器发生错误。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                jsonrpc: '2.0'
                error:
                  code: -32603
                  message: 内部错误
                id: '1'
        '503':
          description: 服务不可用 - 服务暂时不可用。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                jsonrpc: '2.0'
                error:
                  code: -32002
                  message: 服务不可用
                id: '1'
        '504':
          description: 网关超时 - 请求超时。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                jsonrpc: '2.0'
                error:
                  code: -32003
                  message: 网关超时
                id: '1'
      security:
        - ApiKeyQuery: []
components:
  schemas:
    HistoricalAccountQuery:
      type: object
      description: 要读取的历史位置。省略此参数或发送空对象可读取最新的已索引时隙。
      properties:
        slot:
          type: integer
          description: >-
            读取状态的时隙。返回此时隙结束时的账户状态。最早支持的时隙为 444959999，即纪元 1030
            开始时的状态。省略时，读取最新的已索引时隙，但不会超过请求的承诺级别。
          minimum: 444959999
          example: 445000000
        transactionIndex:
          type: integer
          description: 交易在时隙内的位置。返回该交易执行后立即产生的账户状态，而不是时隙结束时的状态。必须指定 slot。
          minimum: 0
          maximum: 16777214
          example: 10
      additionalProperties: false
    DataSliceConfig:
      type: object
      description: 仅返回每个账户数据的一个切片。适用于 base64 和 base64+zstd 编码。
      properties:
        offset:
          type: integer
          description: 开始读取位置的字节偏移量。
          example: 0
        length:
          type: integer
          description: 要返回的字节数。
          example: 8
      required:
        - offset
        - length
    HistoricalContext:
      type: object
      description: 响应元数据。
      properties:
        slot:
          type: integer
          description: 历史存储在处理请求时已索引的最新时隙。这不是你查询的时隙。
          example: 468129571
    HistoricalAccount:
      type: object
      description: 账户在请求位置时的状态，以及该状态最后一次写入的位置。
      properties:
        lamports:
          type: integer
          description: 分配给此账户的 lamport 数量。
          example: 531589475273
        owner:
          type: string
          description: 此账户所分配到的程序的 Base-58 编码公钥。
          example: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
        data:
          description: >-
            账户数据。使用 base64 或 base64+zstd 时，这是一个包含编码后数据和编码方式的双元素数组。使用 jsonParsed
            时，这是一个包含 program、parsed 和 space 的对象。无法解析的账户会回退为 base64 数组。
          oneOf:
            - type: array
              items:
                type: string
            - type: object
              properties:
                program:
                  type: string
                  description: 拥有该账户的程序名称。
                  example: spl-token
                parsed:
                  type: object
                  description: 特定于程序的已解析账户状态。
                space:
                  type: integer
                  description: 账户的数据大小。
                  example: 82
        executable:
          type: boolean
          description: 账户是否包含程序。
          example: false
        rentEpoch:
          type: integer
          description: 此账户下次需要支付租金的纪元。免租账户会报告 u64 的最大值。
        space:
          type: integer
          description: 账户数据大小，以字节为单位。
          example: 82
        lastUpdatedAt:
          $ref: '#/components/schemas/AccountWritePosition'
      required:
        - lamports
        - owner
        - data
        - executable
        - rentEpoch
        - space
        - lastUpdatedAt
    ErrorResponse:
      type: object
      properties:
        jsonrpc:
          type: string
          description: JSON-RPC 协议版本。
          enum:
            - '2.0'
          example: '2.0'
        error:
          type: object
          properties:
            code:
              type: integer
              description: 错误代码。
              example: -32602
            message:
              type: string
              description: 错误消息。
            data:
              type: object
              description: 有关错误的其他数据。
        id:
          type: string
          description: 与请求匹配的标识符。
          example: '1'
    AccountWritePosition:
      type: object
      description: 返回的状态在请求位置或之前最后一次写入的位置。
      properties:
        slot:
          type: integer
          description: >-
            最后一次写入的时隙。如果值为 444959999 且 transactionIndex 为
            null，则表示自历史记录覆盖开始以来，该账户未发生变化。
          example: 444999837
        transactionIndex:
          oneOf:
            - type: integer
            - type: 'null'
          description: 执行最后一次写入的交易位置。如果写入发生在交易之外（例如纪元奖励），或者自历史记录覆盖开始以来账户未发生变化，则为 null。
          example: 700
      required:
        - slot
        - transactionIndex
  securitySchemes:
    ApiKeyQuery:
      type: apiKey
      in: query
      name: api-key
      description: 你的 Helius API 密钥。你可以在[控制面板](https://dashboard.helius.dev/api-keys)中免费获取。

````

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