Get Balance Action
This tool allows the agent to check its own balance, either for the native chain token (ETH/MATIC) or for a specific ERC-20 token.
LLM Usage
Section titled “LLM Usage”The LLM invokes this tool when the user asks questions like:
- “How much ETH do you have?”
- “What’s your USDC balance?”
- “Do you have enough funds to send 5 MATIC to vitalik.eth?”
Arguments
Section titled “Arguments”| Argument | Type | Description |
|---|---|---|
tokenAddress | string | Optional. The contract address of the ERC-20 token to check. If omitted or set to null, the action returns the native token balance. |
Direct Invocation
Section titled “Direct Invocation”import { AgentKit, GetBalanceAction } from "@0xgasless/agent-sdk";
const agentKit = new AgentKit({ apiKey: "YOUR_API_KEY" });const action = new GetBalanceAction();
// Check native balanceconst ethBalance = await action.invoke(agentKit, {});console.log(ethBalance); // "0.5 Native Tokens"
// Check USDC balanceconst usdcBalance = await action.invoke(agentKit, { tokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"});console.log(usdcBalance); // "100.5 USDC"How it works
Section titled “How it works”The action reads the agent’s Smart Account address from the AgentKit context.
- For native balances, it calls
client.getNativeBalance(). - For ERC-20 balances, it calls
client.getTokenBalance(tokenAddress), which automatically fetches the token’s decimals and symbol to format the output nicely for the LLM.
Prompting Tips
Section titled “Prompting Tips”The LLM determines when to use GetBalanceAction. To improve reliability, the SmartTransferAction prompt explicitly tells the LLM: “If you are asked to transfer tokens, you should use GetBalanceAction first to check if you have enough balance.” This multi-step reasoning is handled automatically by LangChain’s ReAct agent loop.