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

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

The question should be specific, self-contained, and written in natural language.
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.
