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

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# How to get a Token Account's Balance

> Learn how to quickly retrieve a Solana token account's balance with a single call. Includes code examples in both TypeScript and Rust.

The token account holds the token balance, which can be retrieved with a single
RPC call.

<Note>
  This example reads a token account that exists only on mainnet. Run it
  against a Surfpool local network that forks mainnet
  (`surfpool start --network mainnet` fetches the account on demand), or point
  the RPC URL at a mainnet endpoint.
</Note>

<Tabs>
<Tab title="Kit">
<div className="sol-tab-label">Kit</div>

```ts highlight={9}
import { address, createSolanaRpc } from "@solana/kit";

const rpc = createSolanaRpc("http://localhost:8899");

const tokenAccountAddress = address(
  "GfVPzUxMDvhFJ1Xs6C9i47XQRSapTd8LHw5grGuTquyQ",
);

const balance = await rpc.getTokenAccountBalance(tokenAccountAddress).send();
console.log(balance);
```

<div className="sol-run" data-run="cookbook/tokens/get-token-balance/balance" data-tab="Kit">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Output from a local Surfpool network</span></div>
<div className="sol-run-out">

```text Output
{
  context: { slot: 438827231n, apiVersion: '4.1.2' },
  value: { uiAmount: 0, decimals: 6, amount: '0', uiAmountString: '0' }
}
```

</div>
</div>

</Tab>
<Tab title="Web3.js v3">
<div className="sol-tab-label">Web3.js v3</div>

```ts highlight={9}
import { Connection, PublicKey } from "@solana/web3.js";

const connection = new Connection("http://localhost:8899", "confirmed");

const tokenAccount = new PublicKey(
  "GfVPzUxMDvhFJ1Xs6C9i47XQRSapTd8LHw5grGuTquyQ",
);

const tokenAmount = await connection.getTokenAccountBalance(tokenAccount);
console.log(`amount: ${tokenAmount.value.amount}`);
console.log(`decimals: ${tokenAmount.value.decimals}`);
```

<div className="sol-run" data-run="cookbook/tokens/get-token-balance/balance" data-tab="Web3.js v3">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Output from a local Surfpool network</span></div>
<div className="sol-run-out">

```text Output
amount: 0
decimals: 6
```

</div>
</div>

</Tab>
<Tab title="Rust">
<div className="sol-tab-label">Rust</div>

```rust
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_commitment_config::CommitmentConfig;
use solana_sdk::pubkey;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let client = RpcClient::new_with_commitment(
        String::from("http://localhost:8899"),
        CommitmentConfig::confirmed(),
    );

    let token_account_address = pubkey!("GfVPzUxMDvhFJ1Xs6C9i47XQRSapTd8LHw5grGuTquyQ");
    let balance = client
        .get_token_account_balance(&token_account_address)
        .await?;
    println!("{:#?}", balance);

    Ok(())
}
```

<div className="sol-run" data-run="cookbook/tokens/get-token-balance/balance" data-tab="Rust">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Output from a local Surfpool network</span></div>
<div className="sol-run-out">

```text Output
UiTokenAmount {
    ui_amount: Some(
        0.0,
    ),
    decimals: 6,
    amount: "0",
    ui_amount_string: "0",
}
```

</div>
</div>

</Tab>
<Tab title="Python">
<div className="sol-tab-label">Python</div>

```py
import asyncio

from solana.rpc.async_api import AsyncClient
from solders.pubkey import Pubkey


async def main():
    async with AsyncClient("http://localhost:8899") as client:
        token_account_address = Pubkey.from_string(
            "GfVPzUxMDvhFJ1Xs6C9i47XQRSapTd8LHw5grGuTquyQ"
        )

        balance = await client.get_token_account_balance(token_account_address)
        print(balance)


asyncio.run(main())
```

<div className="sol-run" data-run="cookbook/tokens/get-token-balance/balance" data-tab="Python">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Output from a local Surfpool network</span></div>
<div className="sol-run-out">

```text Output
GetTokenAccountBalanceResp { context: RpcResponseContext { slot: 461545421, api_version: Some("4.2.1") }, value: UiTokenAmount(UiTokenAmount { ui_amount: Some(0.0), decimals: 6, amount: "0", ui_amount_string: "0" }) }
```

</div>
</div>

</Tab>
<Tab title="Go">
<div className="sol-tab-label">Go</div>

```go
package main

import (
	"context"
	"encoding/json"
	"fmt"

	"github.com/solana-foundation/solana-go/v2"
	"github.com/solana-foundation/solana-go/v2/rpc"
)

func main() {
	client := rpc.New("http://localhost:8899")

	tokenAccountAddress := solana.MustPublicKeyFromBase58("GfVPzUxMDvhFJ1Xs6C9i47XQRSapTd8LHw5grGuTquyQ")

	balance, err := client.GetTokenAccountBalance(context.Background(), tokenAccountAddress, rpc.CommitmentConfirmed)
	if err != nil {
		panic(err)
	}
	out, _ := json.MarshalIndent(balance, "", "  ")
	fmt.Println(string(out))
}
```

<div className="sol-run" data-run="cookbook/tokens/get-token-balance/balance" data-tab="Go">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Output from a local Surfpool network</span></div>
<div className="sol-run-out">

```text Output
{
  "context": {
    "slot": 461555398,
    "apiVersion": "4.2.1"
  },
  "value": {
    "amount": "0",
    "decimals": 6,
    "uiAmount": 0,
    "uiAmountString": "0"
  }
}
```

</div>
</div>

</Tab>
<Tab title="Web3.js (legacy)">
<div className="sol-tab-label">Web3.js (legacy)</div>

<Warning>
  **`@solana/web3.js` 1.x is no longer actively maintained**

  It receives critical fixes only. Use [Kit](/developers/docs/clients/official/javascript#solana-kit) for new code. To migrate existing code, follow the [Kit upgrade guide](https://www.solanakit.com/docs/upgrade-guide), or the [web3.js v3 migration guide](https://github.com/solana-foundation/solana-web3.js/blob/main/docs/web3js-v1-to-v3-migration.md) to keep the class-based API.

  To run this code, install 1.x with `npm install @solana/web3.js@1`. A plain `npm install @solana/web3.js` installs v3, which this code doesn't run on.
</Warning>

```ts highlight={9}
import { Connection, PublicKey } from "@solana/web3.js";

const connection = new Connection("http://localhost:8899", "confirmed");

const tokenAccount = new PublicKey(
  "GfVPzUxMDvhFJ1Xs6C9i47XQRSapTd8LHw5grGuTquyQ",
);

const tokenAmount = await connection.getTokenAccountBalance(tokenAccount);
console.log(`amount: ${tokenAmount.value.amount}`);
console.log(`decimals: ${tokenAmount.value.decimals}`);
```

<div className="sol-run" data-run="cookbook/tokens/get-token-balance/balance" data-tab="Web3.js (legacy)">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Output from a local Surfpool network</span></div>
<div className="sol-run-out">

```text Output
amount: 0
decimals: 6
```

</div>
</div>

</Tab>
</Tabs>

<Info>
  A token account can only hold one kind of mint. When you specify a token
  account, you also specify its mint.
</Info>
