---
title: getTokenAccountsByOwner
description: >-
  Returns SPL Token accounts whose owner matches the supplied address.
url: /docs/rpc/http/gettokenaccountsbyowner
type: reference
hideTableOfContents: true
---

Returns SPL Token accounts whose owner matches the supplied address.

<Callout type="info" title="Source">
  [`get_token_accounts_by_owner`](https://github.com/anza-xyz/agave/blob/v3.1.8/rpc/src/rpc.rs#L2078)
</Callout>

<APIMethod>

```jsonc !!request curl
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getTokenAccountsByOwner",
  "params": [
    // !hover pubkey
    "A1TMhSGzQxMr1TboBKtgixKz1sS6REASMxPo1qsyTSJd",
    // !hover(1:3) token account filter
    {
      // !hover programId
      "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
    },
    // !hover(1:4) config
    {
      // !hover commitment
      "commitment": "finalized",
      // !hover encoding
      "encoding": "jsonParsed"
    }
  ]
}
```

```ts !!request title="Kit"
import { address, createSolanaRpc } from "@solana/kit";

const rpc_url = "https://api.devnet.solana.com";
const rpc = createSolanaRpc(rpc_url);

// !hover pubkey
let owner = address("4kg8oh3jdNtn7j2wcS7TrUua31AgbLzDVkBZgTAe44aF");

// !hover programId
let tokenProgram = address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");

let tokenAccounts = await rpc
  .getTokenAccountsByOwner(
    owner,
    { programId: tokenProgram },
    // !hover(1:4) config
    {
      // !hover commitment
      commitment: "finalized",
      // !hover encoding
      encoding: "jsonParsed"
    }
  )
  .send();

console.log(tokenAccounts);
```

```ts !!request title="web3.js"
import { Connection, PublicKey, clusterApiUrl } from "@solana/web3.js";

const connection = new Connection(clusterApiUrl("devnet"), "confirmed");

// !hover pubkey
let owner = new PublicKey("4kg8oh3jdNtn7j2wcS7TrUua31AgbLzDVkBZgTAe44aF");

// !hover programId
let tokenProgram = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");

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

console.log(tokenAccounts);
```

```rs !!request title="Rust"
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://api.devnet.solana.com"),
        CommitmentConfig::confirmed(),
    );

    // !hover pubkey
    let owner = pubkey!("4kg8oh3jdNtn7j2wcS7TrUua31AgbLzDVkBZgTAe44aF");

    // !hover programId
    let token_program = pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");

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

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

    Ok(())
}
```

### !params

#### !! pubkey

!type string  
!required

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

#### !! token account filter

!type object  
!required

A JSON object with one of the following fields:

##### !! mint

!type string

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

```json title="Example"
{ "mint": "So11111111111111111111111111111111111111112" }
```

##### !! programId

!type string

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

#### !! config

!type object

Configuration object containing the following fields:

##### !! commitment

!type string  
!values processed confirmed finalized  
!default 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 that at least two-thirds of active stake has directly voted to confirm. This is more stable than `processed`, but it is still a weaker guarantee than `finalized`.                                                                       |
| `finalized` | Return data from the highest slot that the cluster recognizes as finalized. In practice, this means the slot has reached maximum vote lockout in validators' vote towers and is recognized by at least two-thirds of active stake. This is the strongest commitment level. |

##### !! minContextSlot

!type number

The minimum slot that the request can be evaluated at

```json title="Example"
{ "minContextSlot": 341197000 }
```

##### !! dataSlice

!type 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.                            |

```json title="Example"
{ "offset": 0, "length": 32 }
```

<Callout type="info">
  Data slicing is only available for `base58`, `base64`, `base64+zstd`, and
  `binary` encodings.
</Callout>

<Callout type="info">
  Use `encoding: "jsonParsed"` if you want the parsed token account structure
  shown in the response example below.
</Callout>

##### !! encoding

!type string  
!values base58 base64 base64+zstd binary jsonParsed  
!default binary

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}` | Falls back to `[data, "base64"]` if no parser found                                                                                                                                                                      |
| `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 |

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](/docs/rpc/json-structures#account-data) wrapper, and
`tokenAmount` uses the same amount fields documented in
[Token Balances](/docs/rpc/json-structures#token-balances).

### !!result

```jsonc !response
{
  "jsonrpc": "2.0",
  // !hover(1:34) result
  "result": {
    // !hover context
    "context": { "apiVersion": "3.1.8", "slot": 341197933 },
    // !hover(1:31) value
    "value": [
      {
        "pubkey": "BGocb4GEpbTFm8UFV2VsDSaBXHELPfAXrvd4vtt8QWrA",
        "account": {
          "data": {
            "program": "spl-token",
            "parsed": {
              "info": {
                "isNative": false,
                "mint": "2cHr7QS3xfuSV8wdxo3ztuF4xbiarF6Nrgx3qpx3HzXR",
                "owner": "A1TMhSGzQxMr1TboBKtgixKz1sS6REASMxPo1qsyTSJd",
                "state": "initialized",
                "tokenAmount": {
                  "amount": "420000000000000",
                  "decimals": 6,
                  "uiAmount": 420000000.0,
                  "uiAmountString": "420000000"
                }
              },
              "type": "account"
            },
            "space": 165
          },
          "executable": false,
          "lamports": 2039280,
          "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
          "rentEpoch": 18446744073709551615,
          "space": 165
        }
      }
    ]
  },
  "id": 1
}
```

!type object

RpcResponse object containing:

#### !! context

!type 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

!type 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](/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}`; if no parser is available, the RPC node falls back to `[data, "base64"]`. |
| `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`                                    | Next epoch at which the account owes rent.                                                                                                                                                                                |
| `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](/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.                                                         |

</APIMethod>
