Overview
agentBuilder is a convenience factory function that creates a fully configured SolanaAgentKit instance with built-in plugins. It simplifies agent creation by automatically:
- Setting up the Solana RPC connection
- Configuring the wallet interface
- Loading default plugins (TokenPlugin and DefiPlugin)
- Applying configuration options
Function signature
Parameters
Object containing wallet function implementations.
Optional configuration object. If not provided, defaults to
{ signOnly: false }.Returns
Fully configured agent instance with the following plugins pre-loaded:
- TokenPlugin - Token operations (balance, transfer, swap, staking)
- DefiPlugin - DeFi operations (lending, borrowing through Rainfi)
agent.methods.Built-in plugins
TheagentBuilder automatically loads these plugins:
TokenPlugin
TokenPlugin
Provides token and wallet management capabilities:Methods:
get_balance()- Get SOL balanceget_token_balance()- Get SPL token balancetransfer()- Transfer SOL or tokenstrade()- Swap tokens via JupiterstakeWithJup()- Stake tokens with JupiterfetchPrice()- Get token pricesgetTokenDataByAddress()- Get token metadatagetTPS()- Get current Solana TPScloseEmptyTokenAccounts()- Clean up empty token accounts
LAUNCH_PUMPFUN_TOKEN action is filtered out for security.DefiPlugin
DefiPlugin
Provides DeFi protocol integrations:Methods:
quoteLoanCalculator()- Calculate loan quotes on RainfiRainfiTransactionBuilder()- Build Rainfi transactionsGetUserLoans()- Retrieve user’s active loansRepayLoan()- Repay loans on Rainfi
Examples
RPC configuration
TheagentBuilder determines the RPC URL in the following order:
- Environment variable:
process.env.NEXT_PUBLIC_SOLANA_RPC - Default fallback: Devnet cluster URL from
@solana/web3.js
For production applications, always set
NEXT_PUBLIC_SOLANA_RPC to a dedicated RPC provider URL (Helius, QuickNode, etc.) for better performance and reliability..env.local
Default agent builder
For testing or development without a connected wallet, usedefaultAgentBuilder:
Type definitions
FNs
Wallet function interface for the agent builder.Best practices
Wallet integration
Wallet integration
Always ensure wallet functions are properly connected before creating the agent:
Error handling
Error handling
Wrap agent operations in try-catch blocks:
Configuration management
Configuration management
Store sensitive configuration in environment variables:
Performance optimization
Performance optimization
Create the agent once and reuse it:
Troubleshooting
Transaction failed: Wallet does not support signAndSendTransaction
Transaction failed: Wallet does not support signAndSendTransaction
Ensure your wallet adapter implements the
signAndSendTransaction method, or set signOnly: true in the config:Method not found in agent.methods
Method not found in agent.methods
The method you’re trying to use might not be available in the default plugins. Check that the required plugin is loaded:
RPC rate limit errors
RPC rate limit errors
Configure a dedicated RPC provider:Consider using rate limit headers and implementing retry logic.
Related
SolanaAgentKit
Core agent class for advanced usage
Plugins
Available plugins and custom plugin development
Wallet integration
Guide to setting up wallet connections
Actions
Working with agent actions