Function Calling for Blockchain Interactions

How function calling connects natural language to protocols & user actions.

How Function Calling Works

Natural Language Input

User provides natural language query like "Trade 100 USDC for ETH"

Function Selection

AI analyzes the query & selects appropriate functions to execute the request.

Execution & Confirmation

Functions execute & return results. User confirms before any on-chain transactions.

Available Functions

Portfolio Functions

All tool names below are the real function names used by the assistant.

get_wallet_net_worth(address: string)
// Returns: totalValue, tokens[] with symbol, balance, value (multi-chain)

getUserProfile(userId: string)
// Returns: user preferences, settings, saved addresses

getTokenPrice(tokenAddress: string, chainId: number)
// Returns: current price, 24h change, market data

Trade Functions

getTradeRoute(params: TradeParams)
// Returns: optimal trade route, expected output, price impact

executeTrade(route: Route, wallet: Wallet)
// Executes: trade transaction, returns receipt

getBridgeRoute(params: BridgeParams)
// Returns: bridge route, estimated time, fees

DeFi Functions

getLendingPosition(address: string, chainId: number)
// Returns: supplied assets, borrowed assets, health factor

supply(params: SupplyParams)
// Executes: supply assets to earn yield

borrow(params: BorrowParams)
// Executes: borrow assets against collateral

Example Flow

example-flow.ts
// User query: "Trade 100 USDC for ETH on Base"

// 1. AI calls getTradeRoute
const route = await getTradeRoute({
  fromToken: 'USDC',
  toToken: 'ETH',
  amount: '100',
  chainId: 8453, // Base
})

// 2. AI presents results to user
console.log(`Expected output: ${route.amountOut} ETH`)
console.log(`Price impact: ${route.priceImpact}%`)

// 3. User confirms
if (userConfirms) {
  // 4. AI calls executeTrade
  const receipt = await executeTrade({
    route,
    wallet: userWallet,
  })
  
  console.log('Transaction confirmed:', receipt.hash)
}
Was this helpful?