Functions
Function calling for blockchain interactions
Learn how we use function calling to interact with protocols & user data. Understand available functions & how natural language queries are translated into 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
get_portfolio_summary(address: string)
// Returns: total value, token balances, allocation
getUserProfile(userId: string)
// Returns: user preferences, settings, saved addresses
getTokenPrice(tokenAddress: string, chainId: number)
// Returns: current price, 24h change, market dataTrade Functions
getEnsoRoute(params: SwapParams)
// Returns: optimal trade route, expected output, price impact
executeEnsoRoute(route: Route, wallet: Wallet)
// Executes: trade transaction, returns receipt
getLifiRoute(params: BridgeParams)
// Returns: bridge route, estimated time, feesDeFi Functions
getAavePosition(address: string, chainId: number)
// Returns: supplied assets, borrowed assets, health factor
supplyToAave(params: SupplyParams)
// Executes: supply assets to Aave
borrowFromAave(params: BorrowParams)
// Executes: borrow assets against collateralExample Flow
example-flow.ts
// User query: "Trade 100 USDC for ETH on Base"
// 1. AI calls getEnsoRoute
const route = await getEnsoRoute({
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 executeEnsoRoute
const receipt = await executeEnsoRoute({
route,
wallet: userWallet,
})
console.log('Transaction confirmed:', receipt.hash)
}Was this helpful?