Skip to Content
Welcome to RitoSwap's documentation!
AI SystemsMCP Stackget_eth_balance

get_eth_balance

dapp/app/lib/mcp/tools/eth-balance.ts provides a raw JSON-schema tool (no zod) that fetches native balances on any supported chain.

Implementation Highlights

  • Validation — Ensures the address matches 0x…40 and chain is one of the enumerated values (mainnet, sepolia, polygon, etc.).
  • RPC selectiongetRpcUrl pulls from public.env.ts/Alchemy for public chains and the local config for ritonet.
  • Result shape — Emits both a helpful sentence and a JSON blob containing wei/ETH values, chain metadata, and the detected symbol.
// dapp/app/lib/mcp/tools/eth-balance.ts const ethBalanceTool: Tool<EthBalanceParams> = { name: 'get_eth_balance', description: 'Get the native token balance of an address on various EVM chains.', inputSchema: EthBalanceInputSchema, async handler({ address, chain = 'mainnet' }) { if (!isValidAddress(address)) fail('Invalid Ethereum address format'); if (!isSupportedChain(chain)) fail(`Unsupported chain: ${chain}`); const rpcUrl = getRpcUrl(chain); const balanceWei = await getBalance(rpcUrl, address); const balanceEth = formatEther(balanceWei); const text = textResult(`Address ${address} on ${formatChainName(chain)} has a balance of ${balanceEth} ${getTokenSymbol(chain)}`); const json = jsonResult({ address, chain, chainName: formatChainName(chain), balanceWei: balanceWei.toString(), balanceEth, symbol: getTokenSymbol(chain) }); return { content: [...text.content, ...json.content] }; }, };

Presenter Integration

dapp/components/chatBot/ToolActivity/catalog/presenters/eth_balance.presenter.ts keeps chips terse:

StatusLabelLogic
pendingFetching BalanceShows no body text so the chip stays compact.
successFetched Balance.Displays X ETH on Chain, pulling the symbol from the JSON payload, falling back to the text stream if needed.
errorFailed to Fetch Balance.Special-cases wallet errors (“Your wallet must be connected…”) via regex.

Notes

get_eth_balance is available to both rapBattle and freestyle modes. Only rap battles impose the “use once per battle” restriction (rapBattleConfig enforces it in the system instructions) while freestyle sessions can call it whenever the runtime allows.

RitoSwap Docs does not store, collect or access any of your conversations. All saved prompts are stored locally in your browser only.