Overview
SolanaAgentKit is the main class for building AI agents that interact with the Solana blockchain. It provides a plugin-based architecture that allows you to extend functionality through modular plugins.
The agent manages wallet operations, blockchain connections, and provides a unified interface for executing blockchain actions through plugins.
Constructor
Creates a new instance of the Solana agent.Wallet implementation that provides transaction signing capabilities. Must implement the
BaseWallet interface with methods for signing transactions and messages.Required methods:publicKey: PublicKey- The wallet’s public keysignTransaction()- Signs a single transactionsignAllTransactions()- Signs multiple transactionssignMessage()- Signs a messagesignAndSendTransaction()- Signs and sends a transactionsendTransaction()(optional) - Sends a transaction
Solana RPC endpoint URL for connecting to the blockchain. Use:
- Mainnet:
https://api.mainnet-beta.solana.com - Devnet:
https://api.devnet.solana.com - Or a custom RPC provider URL
Configuration object for the agent.
Example
Properties
Solana blockchain connection instance. Use this to interact directly with the Solana RPC.
The wallet instance used for signing transactions and messages.
Configuration object containing API keys and settings.
Object containing all methods from registered plugins. The type is dynamically inferred based on plugins added via
use().Array of all registered actions from plugins. Actions define executable operations with schemas and examples.
Methods
use()
Adds a plugin to the agent and registers its methods and actions. Returns a new typed instance with the plugin’s methods available.Plugin object to add to the agent.
SolanaAgentKit instance with updated types including the plugin’s methods.
Behavior:
- If a plugin with the same name is already registered, it returns the existing agent without adding the plugin again
- Calls the plugin’s
initialize()method with the agent instance - Merges plugin methods into
agent.methods - Throws an error if a method name conflicts with an existing method
- Adds all plugin actions to
agent.actions
Example
Type definitions
BaseWallet
Interface for wallet implementations.Plugin
Interface for creating plugins.Action
Interface for defining executable actions with validation.Config
Configuration options for the agent.Best practices
Plugin organization
Plugin organization
Group related functionality into plugins. For example:
- Token operations (balance, transfer, swap)
- DeFi operations (lending, borrowing, staking)
- NFT operations (mint, transfer, list)
Error handling
Error handling
Always wrap agent operations in try-catch blocks:
Sign-only mode
Sign-only mode
Use
signOnly: true when building transactions that will be sent separately:RPC configuration
RPC configuration
Use dedicated RPC providers for production:
- Higher rate limits
- Better reliability
- Advanced features (webhooks, enhanced APIs)
Related
agentBuilder
Factory function for creating pre-configured agents
Plugins
Available plugins for extending agent functionality