# Burn and Close Account

The `Burn and Close Account` tool is part of AgentiPy, allowing users to burn remaining SPL tokens in an account and then close the token account itself on the Solana blockchain. This is useful for cleaning up token accounts that are no longer needed and reclaiming the SOL locked for rent.

## Functionality

This tool is primarily implemented in the `BurnManager` class.

### Key Methods:

* `burn_and_close_account(agent: SolanaAgentKit, token_account: str)`:
  * Checks the balance of the specified `token_account`.
  * If the balance is greater than zero, it creates and adds a `burn` instruction to a transaction.
  * It then adds a `close_account` instruction to the transaction.
  * The transaction also includes compute unit adjustments.
  * Finally, it signs and sends the transaction.
* `process_multiple_accounts(agent: SolanaAgentKit, token_accounts: list)`:
  * Iterates through a list of `token_accounts` (strings).
  * Calls `burn_and_close_account` for each account to process them individually.

**Note:** This tool directly interacts with the Solana blockchain and modifies account states. It requires the agent's wallet to be the owner of the token account or have the necessary authority. Always test thoroughly on a devnet or testnet before using on mainnet.

## Source Code

You can find the source code for this tool on GitHub: <https://github.com/niceberginc/agentipy/blob/main/agentipy/tools/burn_and_close_account.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/burn-and-close-account.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.
