> For the complete documentation index, see [llms.txt](https://docs.agentipy.fun/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.agentipy.fun/tools/get-balance.md).

# Get Balance

The `Get Balance` tool, part of AgentiPy, allows users to fetch the SOL balance or a specific SPL token balance for the agent's wallet on the Solana blockchain.

## Functionality

This tool is implemented in the `BalanceFetcher` class.

### Key Methods:

* `get_balance(agent: SolanaAgentKit, token_address: Optional[Pubkey] = None) -> Optional[float]`:
  * Takes a `SolanaAgentKit` instance and an optional SPL token mint `token_address` (as a `solders.pubkey.Pubkey` object).
  * If `token_address` is not provided, it fetches the native SOL balance of the agent's wallet and returns it in SOL units (float).
  * If `token_address` is provided, it determines the associated token account (ATA) for the agent's wallet and the given mint. It then fetches the balance of this ATA and returns it in its UI amount (float, adjusted for token decimals).
  * Returns `None` if a token account does not exist or has no balance information in the response.
  * Raises an exception if the balance check fails for other reasons.

##

## Source Code

You can find the source code for this tool on GitHub: <https://github.com/niceberginc/agentipy/blob/main/agentipy/tools/get_balance.py>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.agentipy.fun/tools/get-balance.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
