Transfer Tokens

The Transfer Tokens tool, part of AgentiPy, allows users to send SOL (native Solana) or SPL (Solana Program Library) tokens from the agent's wallet to a specified recipient address on the Solana blockchain.

Functionality

This tool is implemented in the TokenTransferManager class.

Key Methods:

  • transfer(agent: SolanaAgentKit, to: str, amount: float, mint: str = None) -> str:

    • Takes a SolanaAgentKit instance, the recipient's public key as a string (to), the amount to transfer (in UI units, e.g., SOL amount or number of SPL tokens), and an optional mint address (string) for SPL tokens.

    • If mint is None, it performs a native SOL transfer. The amount is converted to lamports.

    • If mint is provided, it performs an SPL token transfer.

      • It determines the Associated Token Account (ATA) for both the sender (agent's wallet) and the recipient for the given mint.

      • It fetches the SPL token's mint information to get the decimals for correct amount conversion.

      • It constructs an SPL token transfer instruction.

    • The transaction is signed with the agent's wallet.

    • The raw transaction is sent to the network.

    • Returns the transaction signature as a string.

Note: This tool performs on-chain transactions that will move SOL or SPL tokens from the agent's wallet. Always double-check the recipient address, amount, and network (Devnet/Mainnet) before executing transfers. For SPL token transfers, the sender must have a sufficient balance of the token, and the recipient must have an Associated Token Account (ATA) for that token (though some transfer functions might implicitly create it if needed, this tool's transfer_checked implies the ATA should exist or be creatable by the sender if they are also the payer).

Source Code

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

Last updated