> For the complete documentation index, see [llms.txt](https://docs.triton.one/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.triton.one/solana/rpc-methods/readme/gettokenaccountsbyowner.md).

# getTokenAccountsByOwner

Returns the SPL Token accounts of an owner address, filtered by token mint or token program ID.

{% hint style="info" %}
On Triton shared endpoints, this method is served from Cloudbreak's token index. `processed` is answered at `confirmed`. Queries have a 20-second limit; a query that exceeds it returns error `-32603`. Add a `mint` filter for owners with many token accounts.
{% endhint %}

## Request

{% tabs %}
{% tab title="cURL" %}

```bash
curl "https://<your-endpoint>.mainnet.rpcpool.com/<your-token>" -s -X POST \
  -H "Content-Type: application/json" \
  -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getTokenAccountsByOwner",
  "params": [
    "5wx11hXBHQALycTQNkeQ5w1N9vgup4ardN2yLiDK4JyK",
    {
      "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
    },
    {
      "commitment": "finalized",
      "encoding": "jsonParsed"
    }
  ]
}'
```

{% endtab %}

{% tab title="Kit" %}

```typescript
import { address, createSolanaRpc } from "@solana/kit";

const rpc_url = "https://<your-endpoint>.mainnet.rpcpool.com/<your-token>";
const rpc = createSolanaRpc(rpc_url);

let owner = address("5wx11hXBHQALycTQNkeQ5w1N9vgup4ardN2yLiDK4JyK");

let tokenProgram = address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");

let tokenAccounts = await rpc
  .getTokenAccountsByOwner(
    owner,
    { programId: tokenProgram },
    {
      commitment: "finalized",
      encoding: "jsonParsed"
    }
  )
  .send();

console.log(tokenAccounts);
```

{% endtab %}

{% tab title="web3.js" %}

```typescript
import { Connection, PublicKey } from "@solana/web3.js";

const connection = new Connection("https://<your-endpoint>.mainnet.rpcpool.com/<your-token>", "confirmed");

let owner = new PublicKey("5wx11hXBHQALycTQNkeQ5w1N9vgup4ardN2yLiDK4JyK");

let tokenProgram = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");

let tokenAccounts = await connection.getParsedTokenAccountsByOwner(
  owner,
  { programId: tokenProgram },
  "finalized"
);

console.log(tokenAccounts);
```

{% endtab %}

{% tab title="Rust" %}

```rust
// Cargo.toml: anyhow = "1", solana-client = "~4.4", solana-commitment-config = "3",
// solana-sdk = "5", tokio = { version = "1", features = ["full"] }. solana-client 4.4 takes
// solana-sdk 5.x types. Requires Rust 1.98.1 or newer (solana-client 4.4).
use anyhow::Result;
use solana_client::{nonblocking::rpc_client::RpcClient, rpc_request::TokenAccountsFilter};
use solana_commitment_config::CommitmentConfig;
use solana_sdk::pubkey;

#[tokio::main]
async fn main() -> Result<()> {
    let client = RpcClient::new_with_commitment(
        String::from("https://<your-endpoint>.mainnet.rpcpool.com/<your-token>"),
        CommitmentConfig::confirmed(),
    );

    let owner = pubkey!("5wx11hXBHQALycTQNkeQ5w1N9vgup4ardN2yLiDK4JyK");

    let token_program = pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");

    let token_accounts = client
        .get_token_accounts_by_owner(&owner, TokenAccountsFilter::ProgramId(token_program))
        .await?;

    println!("{:#?}", token_accounts);

    Ok(())
}
```

{% endtab %}
{% endtabs %}

## Parameters

**`pubkey`** · string · required

Pubkey of account owner to query, as base-58 encoded string

**`token account filter`** · object · required

A JSON object with one of the following fields:

**`mint`** · string

Pubkey of the specific token Mint to limit accounts to, as base-58 encoded string

**`programId`** · string

Pubkey of the Token program that owns the accounts, as base-58 encoded string

**`config`** · object

Configuration object containing the following fields:

**`commitment`** · string · default `finalized`

Values: `processed`, `confirmed`, `finalized`

Solana RPC uses the following commitment levels:

| Value       | Description                                                                                                                                                                        |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `processed` | Return data from the highest slot this node has processed on the fork it currently considers best. This is the newest view, but it can still change if the cluster switches forks. |
| `confirmed` | Return data from the highest slot the cluster has finalized. On Alpenglow, `confirmed` and `finalized` are the same level.                                                         |
| `finalized` | Return data from the highest slot that the cluster has finalized. On Alpenglow there are no vote towers or lockouts: a slot is finalized by certificates of aggregated votes.      |

**`minContextSlot`** · number

The minimum slot that the request can be evaluated at

**`dataSlice`** · object

Request a slice of the account's data.

| Field    | Type    | Description                                           |
| -------- | ------- | ----------------------------------------------------- |
| `offset` | `usize` | Byte offset from which to start reading account data. |
| `length` | `usize` | Number of bytes to return.                            |

{% hint style="info" %}
Data slicing is only available for `base58`, `base64`, `base64+zstd`, and `binary` encodings.
{% endhint %}

{% hint style="info" %}
Use `encoding: "jsonParsed"` if you want the parsed token account structure shown in the response example below.
{% endhint %}

**`encoding`** · string · default `binary`

Values: `base58`, `base64`, `base64+zstd`, `binary`, `jsonParsed`

Encoding format for account data.

| Encoding      | Data format                | Notes                                                                                                                                                                                                                    |
| ------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `base64`      | `[data, "base64"]`         | Recommended                                                                                                                                                                                                              |
| `base58`      | `[data, "base58"]`         | Slow. The account's data field must be 128 bytes or fewer                                                                                                                                                                |
| `base64+zstd` | `[data, "base64+zstd"]`    | [Zstandard](https://facebook.github.io/zstd/) compressed                                                                                                                                                                 |
| `jsonParsed`  | `{program, parsed, space}` | Accounts that can't be parsed are left out of the result                                                                                                                                                                 |
| `binary`      | `string`                   | Deprecated. Legacy encoding retained for backwards compatibility. Same base58 encoding as `base58` with the same 128-byte data field limit, but returns data as a plain string instead of an array. Use `base64` instead |

{% hint style="warning" %}
Always set `encoding` to `base64` or `jsonParsed`. Token accounts are 165 bytes or more, so the default `binary` returns error `-32600`.
{% endhint %}

If you use `jsonParsed`, this method returns the token-account wrapper `{program, parsed, space}`. The `program` field identifies the token parser that produced `parsed`.

| `program` value  | Parsed account type     |
| ---------------- | ----------------------- |
| `spl-token`      | SPL Token accounts      |
| `spl-token-2022` | SPL Token 2022 accounts |

The nested `parsed` payload on this page uses the SPL Token account form documented below.

The nested `account` field uses the shared [Account Data](https://solana.com/docs/rpc/json-structures#account-data) wrapper, and `tokenAmount` uses the same amount fields documented in [Token Balances](https://solana.com/docs/rpc/json-structures#token-balances).

## Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "context": { "apiVersion": "4.3.2", "slot": 464671878 },
    "value": [
      {
        "pubkey": "2iFDNrkzUELS4PtWvEKrF3nR54g6LF7T3GU6YEC4VWeN",
        "account": {
          "data": {
            "program": "spl-token",
            "parsed": {
              "info": {
                "isNative": false,
                "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
                "owner": "5wx11hXBHQALycTQNkeQ5w1N9vgup4ardN2yLiDK4JyK",
                "state": "initialized",
                "tokenAmount": {
                  "amount": "0",
                  "decimals": 6,
                  "uiAmount": 0.0,
                  "uiAmountString": "0"
                }
              },
              "type": "account"
            },
            "space": 165
          },
          "executable": false,
          "lamports": 2039280,
          "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
          "rentEpoch": 18446744073709551615,
          "space": 165
        }
      }
    ]
  },
  "id": 1
}
```

## Result

RpcResponse object containing:

**`context`** · object

Slot and API version the node used to answer this request.

| Field        | Type     | Description                                                                     |
| ------------ | -------- | ------------------------------------------------------------------------------- |
| `slot`       | `u64`    | Slot at which the node evaluated this request.                                  |
| `apiVersion` | `string` | RPC API version reported by the node. This field may be omitted by older nodes. |

**`value`** · array

Array of keyed-account objects with the following fields:

| Field     | Type     | Description                                                                                                              |
| --------- | -------- | ------------------------------------------------------------------------------------------------------------------------ |
| `pubkey`  | `string` | Account pubkey, as a base-58 encoded string.                                                                             |
| `account` | `object` | Account data object. Uses the shared [Account Data](https://solana.com/docs/rpc/json-structures#account-data) structure. |

| Field        | Type                                     | Description                                                                                                                                                                                                   |
| ------------ | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `data`       | `string \| [string, encoding] \| object` | Token account data. Binary forms depend on the `encoding` parameter. When `encoding` is `jsonParsed`, this field is `{program, parsed, space}`, and accounts that can't be parsed are left out of the result. |
| `executable` | `bool`                                   | Whether the account contains a program and is therefore read-only.                                                                                                                                            |
| `lamports`   | `u64`                                    | Lamports assigned to the account.                                                                                                                                                                             |
| `owner`      | `string`                                 | Program owner pubkey, as a base-58 encoded string.                                                                                                                                                            |
| `rentEpoch`  | `u64`                                    | Legacy field. Solana no longer collects rent, and rent-exempt accounts report `18446744073709551615` (u64::MAX).                                                                                              |
| `space`      | `u64 \| null`                            | Account data size in bytes. Current Solana RPC responses populate this field for encoded account responses.                                                                                                   |

When `account.data` is returned as an object, it contains:

| Field     | Type     | Description                                                                                                 |
| --------- | -------- | ----------------------------------------------------------------------------------------------------------- |
| `program` | `string` | Name of the parser that produced the decoded token-account data.                                            |
| `parsed`  | `object` | Parsed SPL Token account payload. For this method, this field uses the token-account form documented below. |
| `space`   | `u64`    | Account data size in bytes.                                                                                 |

**`parsed` fields**

| Field  | Type     | Description                       |
| ------ | -------- | --------------------------------- |
| `type` | `string` | Always `account` for this method. |
| `info` | `object` | Parsed SPL Token account fields.  |

**`parsed.info` fields**

| Field               | Type             | Description                                                                                                                       |
| ------------------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `mint`              | `string`         | Token mint pubkey, as a base-58 encoded string.                                                                                   |
| `owner`             | `string`         | Token-account owner pubkey, as a base-58 encoded string.                                                                          |
| `tokenAmount`       | `object`         | Token amount object with raw and decimal-scaled representations.                                                                  |
| `delegate`          | `string \| null` | Delegate pubkey, when a delegate is set.                                                                                          |
| `state`             | `string`         | Token-account state. The value is `uninitialized`, `initialized`, or `frozen`.                                                    |
| `isNative`          | `bool`           | Whether this account wraps the native SOL mint.                                                                                   |
| `rentExemptReserve` | `object \| null` | Rent-exempt reserve amount for wrapped SOL accounts, when present. Uses the same token-amount schema as `tokenAmount`.            |
| `delegatedAmount`   | `object \| null` | Amount delegated to `delegate`, when present. Uses the same token-amount schema as `tokenAmount`.                                 |
| `closeAuthority`    | `string \| null` | Close-authority pubkey, when present.                                                                                             |
| `extensions`        | `array`          | Parsed SPL Token 2022 extension entries. Each element has an `extension` discriminator and an extension-specific `state` payload. |

**`tokenAmount` fields**

This nested amount object uses the same numeric fields documented in [Token Balances](https://solana.com/docs/rpc/json-structures#token-balances).

| Field            | Type             | Description                                                                                |
| ---------------- | ---------------- | ------------------------------------------------------------------------------------------ |
| `uiAmount`       | `number \| null` | Decimal-scaled amount as a floating-point number. Deprecated in favor of `uiAmountString`. |
| `decimals`       | `u8`             | Number of decimal places configured on the mint.                                           |
| `amount`         | `string`         | Raw token amount, as a base-10 integer string.                                             |
| `uiAmountString` | `string`         | Decimal-scaled amount as a string.                                                         |

***

*Adapted from the* [*Solana `getTokenAccountsByOwner` reference*](https://solana.com/docs/rpc/http/gettokenaccountsbyowner)*, maintained by the Solana Foundation.*

***

<i class="fa-life-ring">:life-ring:</i> Contact support by clicking the chat icon in your [customer dashboard](https://customers.triton.one)\ <i class="fa-briefcase">:briefcase:</i> Sales questions? [Contact us](https://triton.one/contact)\ <i class="fa-sparkles">:sparkles:</i> AI agent? Read [llms.txt](https://docs.triton.one/llms.txt)\ <i class="fa-rss">:rss:</i> Follow updates: [Blog](https://blog.triton.one) · [X](https://x.com/triton_one) · [YouTube](https://www.youtube.com/@triton_one_ltd) · [Telegram](https://t.me/tritonone) · [GitHub](https://github.com/rpcpool)
