Skip to main content

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.
new SolanaAgentKit(wallet: BaseWallet, rpc_url: string, config: Config)
wallet
BaseWallet
required
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 key
  • signTransaction() - Signs a single transaction
  • signAllTransactions() - Signs multiple transactions
  • signMessage() - Signs a message
  • signAndSendTransaction() - Signs and sends a transaction
  • sendTransaction() (optional) - Sends a transaction
rpc_url
string
required
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
config
Config
required
Configuration object for the agent.

Example

import { SolanaAgentKit } from '@synto/agent';
import { PublicKey } from '@solana/web3.js';

const agent = new SolanaAgentKit(
  {
    publicKey: new PublicKey('Your...PublicKey'),
    signTransaction: async (tx) => {
      // Sign transaction logic
      return tx;
    },
    signAllTransactions: async (txs) => {
      // Sign multiple transactions
      return txs;
    },
    signMessage: async (message) => {
      // Sign message logic
      return message;
    },
    signAndSendTransaction: async (tx) => {
      // Sign and send transaction
      return { signature: 'tx_signature' };
    },
  },
  'https://api.devnet.solana.com',
  { signOnly: false }
);

Properties

connection
Connection
Solana blockchain connection instance. Use this to interact directly with the Solana RPC.
const blockhash = await agent.connection.getLatestBlockhash();
const balance = await agent.connection.getBalance(publicKey);
wallet
BaseWallet
The wallet instance used for signing transactions and messages.
const publicKey = agent.wallet.publicKey;
const signedTx = await agent.wallet.signTransaction(transaction);
config
Config
Configuration object containing API keys and settings.
const isSignOnly = agent.config.signOnly;
const jupiterFee = agent.config.JUPITER_FEE_BPS;
methods
TPlugins
Object containing all methods from registered plugins. The type is dynamically inferred based on plugins added via use().
// After adding plugins, access their methods
const balance = await agent.methods.get_balance();
const tokenData = await agent.methods.getTokenDataByAddress('mint_address');
actions
Action[]
Array of all registered actions from plugins. Actions define executable operations with schemas and examples.
// List all available actions
const actionNames = agent.actions.map(action => action.name);
console.log('Available actions:', actionNames);

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.
use<P extends Plugin>(plugin: P): SolanaAgentKit<TPlugins & PluginMethods<P>>
plugin
Plugin
required
Plugin object to add to the agent.
Returns: 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

import TokenPlugin from './plugins/plugin-token';
import DefiPlugin from './plugins/plugin-defi';

// Add single plugin
const agentWithToken = agent.use(TokenPlugin);

// Now you can access token methods
await agentWithToken.methods.get_balance();
await agentWithToken.methods.transfer(recipient, amount);

// Chain multiple plugins
const fullAgent = agent
  .use(TokenPlugin)
  .use(DefiPlugin);

// Access methods from both plugins
await fullAgent.methods.trade(inputToken, outputToken, amount);
await fullAgent.methods.quoteLoanCalculator(collateral);

Type definitions

BaseWallet

Interface for wallet implementations.
interface BaseWallet {
  readonly publicKey: PublicKey;
  
  signTransaction<T extends Transaction | VersionedTransaction>(
    transaction: T
  ): Promise<T>;
  
  signAllTransactions<T extends Transaction | VersionedTransaction>(
    transactions: T[]
  ): Promise<T[]>;
  
  sendTransaction?<T extends Transaction | VersionedTransaction>(
    transaction: T
  ): Promise<string>;
  
  signAndSendTransaction<T extends Transaction | VersionedTransaction>(
    transaction: T,
    options?: SendOptions
  ): Promise<{ signature: TransactionSignature }>;
  
  signMessage(message: Uint8Array): Promise<Uint8Array>;
}

Plugin

Interface for creating plugins.
interface Plugin {
  name: string;
  methods: Record<string, any>;
  actions: Action[];
  initialize(agent: SolanaAgentKit): void;
}

Action

Interface for defining executable actions with validation.
interface Action {
  name: string;
  similes: string[];
  description: string;
  examples: ActionExample[][];
  schema: z.ZodType<any>;
  handler: (agent: SolanaAgentKit, input: Record<string, any>) => Promise<Record<string, any>>;
}

Config

Configuration options for the agent.
interface Config {
  signOnly?: boolean;
  OPENAI_API_KEY?: string;
  PERPLEXITY_API_KEY?: string;
  JUPITER_REFERRAL_ACCOUNT?: string;
  JUPITER_FEE_BPS?: number;
  FLASH_PRIVILEGE?: string;
  FLEXLEND_API_KEY?: string;
  HELIUS_API_KEY?: string;
  PRIORITY_LEVEL?: "medium" | "high" | "veryHigh";
  PINATA_JWT?: string;
  PINATA_GATEWAY?: string;
  OTHER_API_KEYS?: Record<string, string>;
}

Best practices

Group related functionality into plugins. For example:
  • Token operations (balance, transfer, swap)
  • DeFi operations (lending, borrowing, staking)
  • NFT operations (mint, transfer, list)
This keeps your code modular and makes it easier to add or remove features.
Always wrap agent operations in try-catch blocks:
try {
  const balance = await agent.methods.get_balance();
  console.log('Balance:', balance);
} catch (error) {
  console.error('Failed to get balance:', error);
}
Use signOnly: true when building transactions that will be sent separately:
const agent = new SolanaAgentKit(wallet, rpcUrl, { signOnly: true });

// Returns signed transaction without sending
const signedTx = await agent.methods.transfer(recipient, amount);

// Send manually with custom logic
const signature = await customSendLogic(signedTx);
Use dedicated RPC providers for production:
  • Higher rate limits
  • Better reliability
  • Advanced features (webhooks, enhanced APIs)
Recommended providers: Helius, QuickNode, Alchemy, Triton

agentBuilder

Factory function for creating pre-configured agents

Plugins

Available plugins for extending agent functionality

Build docs developers (and LLMs) love