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

# getAccountInfo

> 返回与账户关联的所有信息

返回与提供的公钥关联的账户的所有信息。

## 参数

<ParamField query="account" type="string" required>
  要查询的账户公钥（base-58 编码字符串）
</ParamField>

<ParamField query="config" type="object" optional>
  包含以下可选字段的配置对象：

  <Expandable title="config fields">
    <ParamField query="commitment" type="string" optional>
      查询网络时使用的 commitment 级别：

      * `processed`：最新区块（未确认）
      * `confirmed`：超级多数确认
      * `finalized`：超级多数最终确认
    </ParamField>

    <ParamField query="encoding" type="string" optional default="base64">
      账户数据的编码格式：

      * `base58`
      * `base64`
      * `base64+zstd`
      * `jsonParsed`（仅限某些账户类型）
    </ParamField>

    <ParamField query="dataSlice" type="object" optional>
      请求账户数据的切片：

      * `offset`: number - 起始位置（以字节为单位）
      * `length`: number - 返回的字节数
    </ParamField>

    <ParamField query="minContextSlot" type="number" optional>
      请求可被评估的最小 slot
    </ParamField>
  </Expandable>
</ParamField>

## 响应

<ResponseField name="result" type="object | null">
  如果请求的账户不存在，返回 `null`。否则返回包含以下内容的对象：

  <Expandable title="result fields">
    <ResponseField name="context" type="object">
      <ResponseField name="slot" type="number">
        处理请求时的 slot
      </ResponseField>
    </ResponseField>

    <ResponseField name="value" type="object">
      <ResponseField name="lamports" type="number">
        分配给该账户的 lamports 数量
      </ResponseField>

      <ResponseField name="owner" type="string">
        拥有此账户的程序的 base-58 编码公钥
      </ResponseField>

      <ResponseField name="executable" type="boolean">
        该账户是否包含程序
      </ResponseField>

      <ResponseField name="rentEpoch" type="number">
        该账户下次需要支付租金的 epoch
      </ResponseField>

      <ResponseField name="data" type="[string, string] | object">
        账户的数据。格式取决于 encoding 参数：

        * 如果编码为 base58/base64，则为 `[string, encoding]` 元组
        * 如果编码为 "jsonParsed"，则为解析后的 JSON 对象
      </ResponseField>

      <ResponseField name="space" type="number">
        账户数据使用的空间
      </ResponseField>
    </ResponseField>
  </Expandable>
</ResponseField>

## 代码示例

### 基本请求

```bash theme={null}
curl https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getAccountInfo",
  "params": [
    "vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg",
    {
      "encoding": "base58"
    }
  ]
}'
```

### 响应

```json theme={null}
{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "slot": 430
    },
    "value": {
      "data": ["", "base58"],
      "executable": false,
      "lamports": 5000000000,
      "owner": "11111111111111111111111111111111",
      "rentEpoch": 18446744073709551615,
      "space": 0
    }
  },
  "id": 1
}
```

### 带数据切片的请求

```bash theme={null}
curl https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getAccountInfo",
  "params": [
    "vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg",
    {
      "encoding": "base64",
      "dataSlice": {
        "offset": 0,
        "length": 64
      }
    }
  ]
}'
```

### 使用 web3.js

```typescript theme={null}
import { Connection, PublicKey } from '@solana/web3.js';

const connection = new Connection('https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY');
const publicKey = new PublicKey('vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg');

const accountInfo = await connection.getAccountInfo(
  publicKey,
  'confirmed'
);
```

## 注意事项

1. `jsonParsed` 编码仅适用于某些账户类型：
   * 质押账户
   * 代币账户
   * 代币铸造
   * 代币元数据

2. 使用 `dataSlice` 时，数据字段将仅限于请求的切片。

3. 账户数据的编码方式可能因拥有该账户的程序而异。

## 常见错误

| 错误码    | 消息                                       | 解决方案             |
| ------ | ---------------------------------------- | ---------------- |
| -32602 | Invalid param: WrongSize                 | 验证公钥是否有效         |
| -32602 | Invalid param: not base58 encoded string | 确保公钥是 base58 编码的 |
| -32007 | Account not found                        | 请求的账户不存在         |
