> 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/burn-and-close-account.md).

# 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
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/burn-and-close-account.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.
