> ## 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.

# 获取钱包余额

> 检索Solana钱包地址的代币余额和SOL持有量。

每次请求花费 **100 积分**。

## 请求参数

<ParamField body="wallet" type="string" required default="GQUtvPx89ZNCwmvQqFmH59bJcU8fW8siETpaxod7Aydz">
  Solana 钱包地址（base58 编码）
</ParamField>

<ParamField body="page" type="number" default="1">
  分页页码（以1为起始）
</ParamField>

<ParamField body="limit" type="number" default="100">
  每页最大代币数量
</ParamField>

<ParamField body="showZeroBalance" type="boolean" default="false">
  包含余额为零的代币
</ParamField>

<ParamField body="showNative" type="boolean" default="true">
  结果中包含本地SOL
</ParamField>

<ParamField body="showNfts" type="boolean" default="false">
  结果中包含NFT（最多100个，仅限第一页）
</ParamField>


## OpenAPI

````yaml zh/openapi/wallet-api/openapi.yaml GET /v1/wallet/{wallet}/balances
openapi: 3.0.3
info:
  title: Wallet API
  description: |
    一个高性能的REST API，用于查询Solana钱包数据，包括余额、交易记录、转账和身份信息。

    ## 认证

    所有请求都需要通过以下方式传递API密钥：
    - 查询参数：`?api-key=YOUR_API_KEY`
    - 头：`X-Api-Key: YOUR_API_KEY`
  version: 1.0.0
  contact:
    name: API支持
    url: https://helius.dev
servers:
  - url: https://api.helius.xyz
    description: 生产服务器
security:
  - ApiKeyQuery: []
  - ApiKeyHeader: []
tags:
  - name: Identity
    description: 查找钱包身份和已知地址
  - name: Balances
    description: 查询代币和NFT余额
  - name: History
    description: 交易历史和余额变动
  - name: Transfers
    description: 代币转账活动
  - name: Funding
    description: 钱包资金信息
paths:
  /v1/wallet/{wallet}/balances:
    get:
      tags:
        - Balances
      summary: 获取钱包余额
      description: >
        检索钱包的代币和NFT余额。**分页是手动的** - API每个请求最多返回100个代币。


        结果按美元价值降序排序。有定价数据的代币优先显示，然后是没有价格的代币。


        **分页：**使用`page`参数获取更多页面。响应包括`pagination.hasMore`，指示是否有更多结果。每个请求进行一次API调用，成本为100积分。
      operationId: getWalletBalances
      parameters:
        - $ref: '#/components/parameters/WalletAddress'
        - name: page
          in: query
          description: 分页的页码（从1开始）
          schema:
            type: integer
            minimum: 1
            default: 1
          example: 1
        - name: limit
          in: query
          description: 每页的最大代币数量
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 100
          example: 100
        - name: showZeroBalance
          in: query
          description: 包含零余额的代币
          schema:
            type: boolean
            default: false
        - name: showNative
          in: query
          description: 在结果中包含本地SOL
          schema:
            type: boolean
            default: true
        - name: showNfts
          in: query
          description: 在结果中包含NFT（最多100个，仅限第一页）
          schema:
            type: boolean
            default: false
      responses:
        '200':
          description: 成功检索到钱包余额
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BalancesResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  parameters:
    WalletAddress:
      name: wallet
      in: path
      required: true
      description: Solana 钱包地址（base58 编码）
      schema:
        type: string
        pattern: ^[1-9A-HJ-NP-Za-km-z]{32,44}$
        default: GQUtvPx89ZNCwmvQqFmH59bJcU8fW8siETpaxod7Aydz
      example: GQUtvPx89ZNCwmvQqFmH59bJcU8fW8siETpaxod7Aydz
  schemas:
    BalancesResponse:
      type: object
      properties:
        balances:
          type: array
          items:
            $ref: '#/components/schemas/TokenBalance'
          description: >
            当前页面的代币余额数组，包括本机SOL。

            当showNative=true时，SOL作为第一个元素出现，铸币地址为So11111111111111111111111111111111111111112。

            其他代币按美元价值排序 (降序)。
        nfts:
          type: array
          items:
            $ref: '#/components/schemas/Nft'
          description: NFT持有数组（仅在showNfts=true时包含，最多100个，仅限第一页）
        totalUsdValue:
          type: number
          description: 本页面余额的总美元价值（不是总投资组合价值）
          example: 217.98
        pagination:
          type: object
          description: 分页元数据。用户必须使用页面参数手动请求更多页面。
          properties:
            page:
              type: integer
              description: 当前页码
              example: 1
            limit:
              type: integer
              description: 每页项目数
              example: 100
            hasMore:
              type: boolean
              description: 如果有更多结果可用则为真。增加页面参数以获取下一页。
              example: true
          required:
            - page
            - limit
            - hasMore
      required:
        - balances
        - totalUsdValue
        - pagination
    TokenBalance:
      type: object
      properties:
        mint:
          type: string
          description: Token 铸造地址
          example: So11111111111111111111111111111111111111112
        symbol:
          type: string
          nullable: true
          description: Token 符号
          example: SOL
        name:
          type: string
          nullable: true
          description: Token 名称
          example: Solana
        balance:
          type: number
          description: Token 余额（调整小数位后）
          example: 1.5
        decimals:
          type: integer
          description: 小数位数
          example: 9
        pricePerToken:
          type: number
          nullable: true
          description: 每个Token的美元价格
          example: 145.32
        usdValue:
          type: number
          nullable: true
          description: 持有资产的美元总价值
          example: 217.98
        logoUri:
          type: string
          nullable: true
          description: 代币徽标图像的URL
          example: https://example.com/sol-logo.png
        tokenProgram:
          type: string
          enum:
            - spl-token
            - token-2022
          description: 代币程序类型（spl-token用于传统，token-2022用于新标准）
          example: spl-token
      required:
        - mint
        - balance
        - decimals
        - tokenProgram
    Nft:
      type: object
      properties:
        mint:
          type: string
          description: NFT铸造地址
          example: 7Xq8wXyXVqfBPPqVJjPDwG9zN5wCVxBYZ6z7vPYBzr6F
        name:
          type: string
          nullable: true
          description: NFT名称
          example: Degen Ape
        imageUri:
          type: string
          nullable: true
          description: NFT图像URI
          example: https://example.com/nft.png
        collectionName:
          type: string
          nullable: true
          description: 收藏名称
          example: Degen Ape Academy
        collectionAddress:
          type: string
          nullable: true
          description: 集合地址
          example: DegN1dXmU2uYa4n7U9qTh7YNYpK4u8L9qXx7XqYqJfGH
        compressed:
          type: boolean
          description: 是否为压缩NFT
          example: false
      required:
        - mint
        - compressed
    Error:
      type: object
      properties:
        error:
          type: string
          description: 错误信息
          example: 无效的钱包地址
        code:
          type: integer
          description: HTTP状态代码
          example: 400
        details:
          type: string
          description: 附加错误详情
          example: '''invalid-address'' 不是有效的 Solana 地址'
      required:
        - error
        - code
  responses:
    BadRequest:
      description: 无效的请求参数
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: 无效的钱包地址
            code: 400
            details: '''invalid-address''不是有效的Solana地址'
    Unauthorized:
      description: 缺少或无效的API密钥
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: 需要API密钥。通过?api-key=xxx或X-Api-Key头传递
            code: 401
    RateLimited:
      description: 超出速率限制。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: RATE_LIMIT_EXCEEDED
            code: 429
            details: 请求过多。请在 2 秒后重试。
    InternalError:
      description: 临时服务器错误。可以使用指数退避重试。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: INTERNAL_ERROR
            code: 500
            details: 发生意外错误。请重试。
  securitySchemes:
    ApiKeyQuery:
      type: apiKey
      in: query
      name: api-key
      description: 作为查询参数传递的API密钥
    ApiKeyHeader:
      type: apiKey
      in: header
      name: X-Api-Key
      description: 在请求头中传递的API密钥

````