Skip to main content

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
This is the recommended way to create agents in Synto Mobile applications.

Function signature

agentBuilder(fns: FNs, config?: Config): SolanaAgentKit

Parameters

fns
FNs
required
Object containing wallet function implementations.
config
Config
Optional configuration object. If not provided, defaults to { signOnly: false }.

Returns

agent
SolanaAgentKit
Fully configured agent instance with the following plugins pre-loaded:
  • TokenPlugin - Token operations (balance, transfer, swap, staking)
  • DefiPlugin - DeFi operations (lending, borrowing through Rainfi)
The agent is ready to use with all plugin methods available via agent.methods.

Built-in plugins

The agentBuilder automatically loads these plugins:
Provides token and wallet management capabilities:Methods:
  • get_balance() - Get SOL balance
  • get_token_balance() - Get SPL token balance
  • transfer() - Transfer SOL or tokens
  • trade() - Swap tokens via Jupiter
  • stakeWithJup() - Stake tokens with Jupiter
  • fetchPrice() - Get token prices
  • getTokenDataByAddress() - Get token metadata
  • getTPS() - Get current Solana TPS
  • closeEmptyTokenAccounts() - Clean up empty token accounts
Note: The LAUNCH_PUMPFUN_TOKEN action is filtered out for security.
Provides DeFi protocol integrations:Methods:
  • quoteLoanCalculator() - Calculate loan quotes on Rainfi
  • RainfiTransactionBuilder() - Build Rainfi transactions
  • GetUserLoans() - Retrieve user’s active loans
  • RepayLoan() - Repay loans on Rainfi
Supports lending and borrowing operations through the Rainfi protocol.

Examples

import { agentBuilder } from '@synto/agent';
import { useWallet } from '@solana/wallet-adapter-react';

function MyComponent() {
  const wallet = useWallet();
  
  const agent = agentBuilder(
    {
      publicKey: wallet.publicKey!,
      signTransaction: wallet.signTransaction!,
      signAllTransactions: wallet.signAllTransactions!,
      signMessage: wallet.signMessage!,
      signAndSendTransaction: async (tx) => {
        const signature = await wallet.sendTransaction(tx, connection);
        return { signature };
      },
      sendTransaction: async (tx) => {
        return await wallet.sendTransaction(tx, connection);
      },
    },
    {
      JUPITER_FEE_BPS: 50, // 0.5% referral fee
      PRIORITY_LEVEL: 'high',
    }
  );
  
  // Use the agent
  const balance = await agent.methods.get_balance();
  
  return <View>{/* Your UI */}</View>;
}

RPC configuration

The agentBuilder determines the RPC URL in the following order:
  1. Environment variable: process.env.NEXT_PUBLIC_SOLANA_RPC
  2. 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
NEXT_PUBLIC_SOLANA_RPC=https://mainnet.helius-rpc.com/?api-key=YOUR_KEY

Default agent builder

For testing or development without a connected wallet, use defaultAgentBuilder:
import { defaultAgentBuilder } from '@synto/agent';

const agent = defaultAgentBuilder();

// This agent has all plugins loaded but with stub wallet functions
// Useful for:
// - Testing UI components
// - Development without wallet connection
// - Simulating agent behavior
defaultAgentBuilder() creates an agent with empty/stub wallet functions. It cannot sign or send real transactions. Only use it for testing and development.

Type definitions

FNs

Wallet function interface for the agent builder.
type FNs = {
  signAndSendTransaction: <T extends Transaction | VersionedTransaction>(
    transaction: T
  ) => Promise<{ signature: TransactionSignature }>;
  
  signTransaction: <T extends Transaction | VersionedTransaction>(
    transaction: T
  ) => Promise<T>;
  
  signMessage: (msg: Uint8Array) => Promise<Uint8Array>;
  
  sendTransaction: <T extends Transaction | VersionedTransaction>(
    transaction: T
  ) => Promise<string>;
  
  signAllTransactions: <T extends Transaction | VersionedTransaction>(
    transactions: T[]
  ) => Promise<T[]>;
  
  publicKey: PublicKey;
}

Best practices

Always ensure wallet functions are properly connected before creating the agent:
if (!wallet.connected || !wallet.publicKey) {
  throw new Error('Wallet not connected');
}

const agent = agentBuilder({
  publicKey: wallet.publicKey,
  // ... other functions
});
Wrap agent operations in try-catch blocks:
try {
  const result = await agent.methods.transfer(recipient, amount);
  console.log('Success:', result);
} catch (error) {
  if (error.message.includes('insufficient funds')) {
    // Handle insufficient balance
  } else if (error.message.includes('User rejected')) {
    // Handle user rejection
  } else {
    // Handle other errors
  }
}
Store sensitive configuration in environment variables:
const agent = agentBuilder(walletFunctions, {
  HELIUS_API_KEY: process.env.HELIUS_API_KEY,
  JUPITER_REFERRAL_ACCOUNT: process.env.JUPITER_REFERRAL,
  JUPITER_FEE_BPS: Number(process.env.JUPITER_FEE_BPS),
});
Create the agent once and reuse it:
// In React
const agent = useMemo(
  () => agentBuilder(walletFunctions, config),
  [wallet.publicKey] // Only recreate when wallet changes
);

Troubleshooting

Ensure your wallet adapter implements the signAndSendTransaction method, or set signOnly: true in the config:
const agent = agentBuilder(walletFunctions, { signOnly: true });
The method you’re trying to use might not be available in the default plugins. Check that the required plugin is loaded:
// List available methods
console.log(Object.keys(agent.methods));

// Add custom plugin if needed
const extendedAgent = agent.use(customPlugin);
Configure a dedicated RPC provider:
NEXT_PUBLIC_SOLANA_RPC=https://your-dedicated-rpc.com
Consider using rate limit headers and implementing retry logic.

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

Build docs developers (and LLMs) love