> For the complete documentation index, see [llms.txt](https://kaze-ai.gitbook.io/kaze-ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kaze-ai.gitbook.io/kaze-ai/token-operations/transfer-sol-and-spl-tokens.md).

# Transfer SOL & SPL tokens

This page provides a comprehensive guide to transferring native SOL and SPL tokens using**Kaze AI**’s toolkit. Below is an explanation of the key components, functionalities, and implementation steps.

**Overview**

The `SolanaTransferHelper` and `TokenTransferManager` classes enable developers to execute, manage, and verify token transfers seamlessly. These tools support:

* Transferring **native SOL** to any recipient.
* Transferring **SPL tokens**, including validation and associated token account management.
* Tracking transfer history and verifying transaction success.

***

**Code Explanation**

**1. Native SOL Transfer**

The `transfer_native_sol` method performs native SOL transfers by:

* Creating a transaction that specifies the sender, recipient, and amount.
* Sending the transaction using the `AsyncClient` and awaiting confirmation.

Copy

```
async def transfer_native_sol(agent: SolanaAgentKit, to: Pubkey, amount: float) -> str:
    # Create and send transaction for native SOL transfer
```

**2. SPL Token Transfer**

The `transfer_spl_tokens` method allows SPL token transfers with:

* Validation of token mint initialization and associated token accounts.
* Calculation of the exact token amount, accounting for decimal precision.
* Execution of the transfer using the `transfer_checked` instruction.

Copy

```
async def transfer_spl_tokens(rpc_client: AsyncClient, agent: SolanaAgentKit, recipient: Pubkey, spl_token: Pubkey, amount: float) -> str:
    # Perform token transfer with validation and error handling
```

**3. Confirming Transactions**

The `confirm_transaction` method ensures successful processing of transactions.

Copy

```
async def confirm_transaction(agent: SolanaAgentKit, signature: str) -> None:
    # Confirm transaction on the blockchain
```

**4. Transfer Execution**

The `TokenTransferManager` class manages transfers by:

* Handling both SOL and SPL token transfers dynamically.
* Storing a history of transfers and verifying transaction success.

Copy

```
async def execute_transfer(to: Pubkey, amount: float, mint: Optional[Pubkey] = None) -> TransferResult:
    # Execute either SOL or SPL token transfer based on parameters
```

***

**Key Features**

1. **Native SOL Transfers** Send SOL with just a recipient's address and the desired amount.
2. **SPL Token Transfers** Fully handle SPL token transfers, including mint validation and error detection.
3. **Transaction Verification** Verify the success of transfers directly through the blockchain.
4. **Transfer History Management** Access a complete record of executed transfers for auditing and debugging.

***

**How to Use**

* **Setup**: Import the required classes and initialize a `SolanaAgentKit` with your wallet.
* **Native SOL Transfer Example**:

  Copy

  ```
  await SolanaTransferHelper.transfer_native_sol(agent, recipient_address, amount)
  ```
* **SPL Token Transfer Example**:

  Copy

  ```
  await SolanaTransferHelper.transfer_spl_tokens(rpc_client, agent, recipient_address, token_mint_address, amount)
  ```
* **Verification Example**:

  Copy

  ```
  is_successful = await TokenTransferManager.verify_transfer(transfer_result)
  ```

***

**Error Handling**

* Ensure the mint and associated token accounts are initialized for SPL transfers.
* Handle insufficient funds or invalid decimal values gracefully.


---

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

```
GET https://kaze-ai.gitbook.io/kaze-ai/token-operations/transfer-sol-and-spl-tokens.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.
