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

# getAssetsByOwner

> 在 OrbitFlare 上使用 DAS getAssetsByOwner，列出某个 Solana 钱包拥有的所有 NFT、压缩 NFT、MPL Core 资产和代币，并附带 SOL 余额和美元价格。

## 概述

`getAssetsByOwner` 列出某个钱包持有的资产。默认情况下，它返回 NFT、压缩 NFT 和 MPL Core 资产。添加 `showFungible` 可包含同质化代币及其余额和美元价格，添加 `showNativeBalance` 可附加钱包的 SOL 余额。两者结合即可在一次调用中获得完整的资产组合。

## 参数

<ResponseField name="ownerAddress" type="string" required>
  钱包地址（base-58）。
</ResponseField>

<ResponseField name="page" type="number">
  页码，从 1 开始。请参阅[分页](/cn/das-api/pagination)。
</ResponseField>

<ResponseField name="limit" type="number">
  每页结果数。最大值和默认值均为 1,000。
</ResponseField>

<ResponseField name="cursor" type="string">
  来自上一次响应的游标。
</ResponseField>

<ResponseField name="before" type="string">
  返回 ID 在此 ID 之前的资产。
</ResponseField>

<ResponseField name="after" type="string">
  返回 ID 在此 ID 之后的资产。
</ResponseField>

<ResponseField name="sortBy" type="object">
  `{ "sortBy": "id" | "created" | "updated" | "recent_action" | "none", "sortDirection": "asc" | "desc" }`
</ResponseField>

<ResponseField name="options" type="object">
  [显示选项](/cn/das-api/display-options)：`showFungible`、`showNativeBalance`、`showUnverifiedCollections`、`showCollectionMetadata`、`showInscription`。也可以作为 `displayOptions` 传入。
</ResponseField>

## 响应

<ResponseField name="result" type="object">
  <Expandable title="result 字段">
    <ResponseField name="last_indexed_slot" type="number">
      索引已处理的最新 slot。
    </ResponseField>

    <ResponseField name="total" type="number">
      本页中的条目数。
    </ResponseField>

    <ResponseField name="limit" type="number">
      使用的每页大小。
    </ResponseField>

    <ResponseField name="page" type="number">
      按页码分页时的页码。
    </ResponseField>

    <ResponseField name="cursor" type="string">
      按游标分页时，用于获取下一页的游标。
    </ResponseField>

    <ResponseField name="items" type="array">
      [资产对象](/cn/das-api/asset-object)。
    </ResponseField>

    <ResponseField name="nativeBalance" type="object">
      使用 `showNativeBalance` 时返回：`lamports`、`price_per_sol` 和 `total_price`（美元）。
    </ResponseField>
  </Expandable>
</ResponseField>

## 代码示例

### 请求

```bash theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
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": "getAssetsByOwner",
  "params": {
    "ownerAddress": "86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY",
    "page": 1,
    "limit": 100,
    "options": {
      "showFungible": true,
      "showNativeBalance": true
    }
  }
}'
```

### 响应

```json theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
{
  "jsonrpc": "2.0",
  "result": {
    "last_indexed_slot": 457714577,
    "total": 100,
    "limit": 100,
    "page": 1,
    "nativeBalance": {
      "lamports": 1328527472954,
      "price_per_sol": 101.5,
      "total_price": 134845.54
    },
    "items": [
      {
        "interface": "FungibleToken",
        "id": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
        "token_info": {
          "symbol": "USDC",
          "balance": 2500000,
          "decimals": 6,
          "token_program": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
          "price_info": {
            "price_per_token": 1.0,
            "total_price": 2.5,
            "currency": "USDC"
          }
        }
      }
    ]
  },
  "id": 1
}
```

此处的数值仅作示意，资产对象也已做精简。所有字段请参阅[资产对象](/cn/das-api/asset-object)。

### TypeScript

```typescript theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
const RPC_URL = 'https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY';

async function getPortfolio(owner: string) {
  const response = await fetch(RPC_URL, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      jsonrpc: '2.0',
      id: 1,
      method: 'getAssetsByOwner',
      params: {
        ownerAddress: owner,
        page: 1,
        limit: 1000,
        options: { showFungible: true, showNativeBalance: true },
      },
    }),
  });
  const { result, error } = await response.json();
  if (error) throw new Error(error.message);

  const nfts = result.items.filter((a: any) => a.ownership.ownership_model === 'single');
  const tokens = result.items.filter((a: any) => a.ownership.ownership_model === 'token');
  const tokenUsd = tokens.reduce(
    (sum: number, t: any) => sum + (t.token_info?.price_info?.total_price ?? 0),
    0,
  );

  return {
    nfts,
    tokens,
    solUsd: result.nativeBalance?.total_price ?? 0,
    tokenUsd,
  };
}
```

## 常见错误

| 错误码 | 消息 | 解决方案 |
| - | - | - |
| -32602 | Pubkey Validation Err: ... is invalid | 传入有效的 base-58 钱包地址 |
| -32602 | Pagination Error. Limit should not be greater than 1000. | 使用不超过 1,000 的 `limit` |
| -32602 | Pagination Error. Only one pagination parameter supported per query. | 在 `page`、`cursor` 或 `before`/`after` 中只使用一种 |
| -32602 | Pagination Sorting Error | 游标和范围需要 `sortBy: "id"`；其他排序方式请使用 `page` |


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