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

# 历史 getAccountInfo RPC 方法

> 读取 Solana 账户在任意过去 slot 的状态，或逐次查看账户更新。查看历史 getAccountInfo 的参数、限制和代码示例。

使用标准的 **getAccountInfo** 方法读取账户过去的状态。在配置对象中添加以下其中一项：

* `slot`：账户在该 slot 结束时的状态。
* `lastUpdateBeforeSlot`：账户在该 slot 之前（不含）最后一次更新后的状态。
* `firstUpdateAfterSlot`：账户在该 slot 之后（不含）第一次更新后的状态。

只能设置其中一项。都不设置时，`getAccountInfo` 返回账户的当前状态，见 [getAccountInfo](https://docs.solanatracker.io/cn/solana-rpc/http/getaccountinfo.md)。

## 遍历账户历史

使用 `lastUpdateBeforeSlot` 和 `firstUpdateAfterSlot` 时，`context.slot` 是返回的那次更新所在的 slot。把它传回请求，即可逐次遍历账户的历史。

添加 `changes`（1 到 20）可在 `result.changes` 中同时获得相应数量的更早版本，按从新到旧排列，每个版本包含 `slot`、`blockTime` 和 `txnSignature`。

## 限制

* 历史读取返回 finalized 数据。`commitment` 会被忽略，`minContextSlot` 不能与这些选项同时使用。
* 账户在该时间点不存在或已关闭，或没有可用数据时，`value` 为 `null`。
* **SPL Token 和 Token-2022 的 mint 账户**无法按历史读取：返回错误 `-32033`，`data.reason` 为 `"splTokenMint"`。Stake、vote、config 和 sysvar 账户也返回 `-32033`。
* **代币账户**根据其余额历史重建。会返回余额、mint、所有者和租金 lamports；不返回 Token-2022 扩展、委托人、冻结状态、关闭权限和精确的 `space`。
* 晚于最新可用 slot 的 slot 返回 `-32030`，早于最早可用 slot 的返回 `-32031`，没有可用数据的 slot 返回 `-32034`。`lastUpdateBeforeSlot` 或 `firstUpdateAfterSlot` 遍历超过第一次或最后一次已知更新时返回 `-32020`。
* `dataSlice` 不能与 `jsonParsed` 或 `jsonParsedEnhanced` 同时使用。

一次历史读取消耗 1 积分，与实时调用相同。一次读取多个账户，请使用[历史 getMultipleAccounts](https://docs.solanatracker.io/cn/solana-rpc/http/historical-getmultipleaccounts.md)。

请求配置和错误处理见 [RPC 快速入门](https://docs.solanatracker.io/cn/solana-rpc/quickstart.md)。计费见[积分与限制](https://docs.solanatracker.io/cn/solana-rpc/credits-and-rate-limits.md)。


## OpenAPI

````yaml historical-getaccountinfo post /
openapi: 3.1.0
info:
  title: Solana RPC
  version: 1.0.0
  description: Solana JSON RPC API
servers:
  - url: https://rpc-mainnet.solanatracker.io
security: []
paths:
  /:
    post:
      summary: Historical getAccountInfo
      description: >-
        Read an account as it was at a past slot, or step through its updates
        one at a time. Send `getAccountInfo` with `slot`, `lastUpdateBeforeSlot`
        or `firstUpdateAfterSlot` in the config object.
      operationId: historical-getaccountinfo
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GetAccountInfoRequest'
            examples:
              historicalAtSlot:
                summary: Historical read at a slot
                value:
                  jsonrpc: '2.0'
                  id: 1
                  method: getAccountInfo
                  params:
                    - 7xK1a6Ut1pCrH9CiMwdEqx7RyhqgUZRux692Sg4m1TTw
                    - encoding: base64
                      slot: 411108200
              historicalLastUpdateBefore:
                summary: Most recent update before a slot, with earlier versions
                value:
                  jsonrpc: '2.0'
                  id: 1
                  method: getAccountInfo
                  params:
                    - 7xK1a6Ut1pCrH9CiMwdEqx7RyhqgUZRux692Sg4m1TTw
                    - encoding: base64
                      lastUpdateBeforeSlot: 411108200
                      changes: 2
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetAccountInfoResponse'
              examples:
                historicalAtSlot:
                  summary: Historical read at a slot
                  value:
                    jsonrpc: '2.0'
                    result:
                      context:
                        apiVersion: 4.2.1
                        slot: 411108200
                      value:
                        data:
                          - ''
                          - base64
                        executable: false
                        lamports: 1523847120
                        owner: '11111111111111111111111111111111'
                        rentEpoch: 18446744073709552000
                        space: 0
                    id: 1
                splTokenMint:
                  summary: SPL Token mint (not available historically)
                  value:
                    jsonrpc: '2.0'
                    error:
                      code: -32033
                      message: >-
                        Historic SPL Token mint state is not archived:
                        EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
                      data:
                        pubkeys:
                          - EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
                        reason: splTokenMint
                    id: 1
      security:
        - ApiKeyQuery: []
components:
  schemas:
    GetAccountInfoRequest:
      type: object
      required:
        - jsonrpc
        - id
        - method
        - params
      properties:
        jsonrpc:
          type: string
          enum:
            - '2.0'
        id:
          type: integer
        method:
          type: string
          enum:
            - getAccountInfo
        params:
          type: array
          minItems: 2
          maxItems: 2
          items:
            - type: string
              description: Pubkey of account to query, as base-58 encoded string
            - type: object
              description: >-
                Required. Set exactly one of `slot`, `lastUpdateBeforeSlot` or
                `firstUpdateAfterSlot`. Historical reads always return finalized
                data.
              properties:
                encoding:
                  type: string
                  enum:
                    - base58
                    - base64
                    - base64+zstd
                    - jsonParsed
                    - jsonParsedEnhanced
                  description: >-
                    Encoding format for account data. `jsonParsedEnhanced` is
                    `jsonParsed` plus Anchor IDL decoding of account data the
                    standard parser leaves unparsed. It costs no extra credits.
                dataSlice:
                  type: object
                  description: >-
                    Request a slice of the account's data. Not allowed with
                    `jsonParsed` or `jsonParsedEnhanced`.
                  properties:
                    offset:
                      type: integer
                      description: Byte offset from which to start reading
                    length:
                      type: integer
                      description: Number of bytes to read
                slot:
                  type: integer
                  description: >-
                    return the account as it was at the end of this slot (the
                    last update at or before it). Set at most one of `slot`,
                    `lastUpdateBeforeSlot` and `firstUpdateAfterSlot`.
                  example: 411108200
                lastUpdateBeforeSlot:
                  type: integer
                  description: >-
                    return the account as of its most recent update strictly
                    before this slot. Set at most one of `slot`,
                    `lastUpdateBeforeSlot` and `firstUpdateAfterSlot`.
                    `context.slot` is the slot of that update, so you can pass
                    it back to walk the account's history.
                  example: 411108200
                firstUpdateAfterSlot:
                  type: integer
                  description: >-
                    return the account as of its first update strictly after
                    this slot. Set at most one of `slot`, `lastUpdateBeforeSlot`
                    and `firstUpdateAfterSlot`. `context.slot` is the slot of
                    that update, so you can pass it back to walk the account's
                    history.
                  example: 411000000
                changes:
                  type: integer
                  minimum: 1
                  maximum: 20
                  description: >-
                    Also return up to this many earlier versions of the account,
                    newest first, strictly before the requested slot, in
                    `result.changes`.
                  example: 5
          default:
            - 7xK1a6Ut1pCrH9CiMwdEqx7RyhqgUZRux692Sg4m1TTw
            - encoding: base64
              slot: 411108200
    GetAccountInfoResponse:
      type: object
      properties:
        jsonrpc:
          type: string
          enum:
            - '2.0'
        result:
          type: object
          properties:
            context:
              type: object
              properties:
                slot:
                  type: integer
                  description: >-
                    The slot at which the data was retrieved. For
                    `lastUpdateBeforeSlot` and `firstUpdateAfterSlot`, the slot
                    of the update returned.
                apiVersion:
                  type: string
                  description: The Solana API version
            value:
              oneOf:
                - type: 'null'
                  description: >-
                    If the account doesn't exist. On a historical read: the
                    account did not exist or was closed at that point, or no
                    data is known for it.
                - type: object
                  properties:
                    data:
                      oneOf:
                        - type: array
                          description: '[data, encoding] pair for base58/base64'
                          items:
                            - type: string
                            - type: string
                        - type: object
                          description: Parsed data object when jsonParsed encoding is used
                    executable:
                      type: boolean
                      description: Boolean indicating if the account contains a program
                    lamports:
                      type: integer
                      description: Number of lamports assigned to this account
                    owner:
                      type: string
                      description: >-
                        Base-58 encoded Pubkey of the program this account has
                        been assigned to
                    rentEpoch:
                      type: integer
                      description: The epoch at which this account will next owe rent
                    space:
                      type: integer
                      description: The data size of the account
            changes:
              type: array
              description: >-
                Only with `changes`: earlier versions of the account, newest
                first. Each is an account object in the requested encoding with
                the update's slot, block time and transaction signature added.
              items:
                type: object
                properties:
                  data:
                    description: Account data in the requested encoding.
                  executable:
                    type: boolean
                  lamports:
                    type: integer
                  owner:
                    type: string
                  rentEpoch:
                    type: integer
                  space:
                    type: integer
                  slot:
                    type: integer
                    description: Slot of the update.
                  blockTime:
                    type: integer
                    description: Block time of the update, in Unix seconds.
                  txnSignature:
                    type: string
                    description: Signature of the transaction that made the update.
        id:
          type: integer
  securitySchemes:
    ApiKeyQuery:
      type: apiKey
      in: query
      name: api_key

````

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