get_etf_balance
Check ETF token balance for any wallet address across multiple EVM chains. Retrieve balance information by specifying chain ID and token address.
Instructions
Get ETF token balance for a wallet address.
Args:
chain_id: Chain ID (1, 10, 56, 100, 137, 8453, 42161)
etf_token_address: Address of the ETF token
wallet_address: Wallet address to check (defaults to server wallet)
Returns:
JSON string with ETF token balance information.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chain_id | Yes | ||
| etf_token_address | Yes | ||
| wallet_address | No |
Implementation Reference
- padex.py:1028-1092 (handler)The handler function implementing the get_etf_balance tool. It retrieves the ERC20 token balance of a specified ETF token for a wallet on a given EVM chain using Web3.py, formats it into JSON with chain details, token info, and human-readable balance.async def get_etf_balance(ctx: Context, chain_id: str, etf_token_address: str, wallet_address: Optional[str] = None) -> str: """Get ETF token balance for a wallet address. Args: chain_id: Chain ID (1, 10, 56, 100, 137, 8453, 42161) etf_token_address: Address of the ETF token wallet_address: Wallet address to check (defaults to server wallet) Returns: JSON string with ETF token balance information. """ try: paloma_ctx = ctx.request_context.lifespan_context if chain_id not in CHAIN_CONFIGS: return f"Error: Unsupported chain ID {chain_id}" config = CHAIN_CONFIGS[chain_id] # Use server wallet if no address provided if wallet_address is None: wallet_address = paloma_ctx.address # Validate addresses if not Web3.is_address(etf_token_address): return f"Error: Invalid ETF token address format: {etf_token_address}" if not Web3.is_address(wallet_address): return f"Error: Invalid wallet address format: {wallet_address}" if chain_id not in paloma_ctx.web3_clients: return f"Error: Web3 client not available for {config.name}" web3 = paloma_ctx.web3_clients[chain_id] etf_contract = web3.eth.contract( address=etf_token_address, abi=ERC20_ABI ) # Get token info try: balance_wei = etf_contract.functions.balanceOf(wallet_address).call() decimals = etf_contract.functions.decimals().call() symbol = etf_contract.functions.symbol().call() balance = balance_wei / (10 ** decimals) except Exception as e: return f"Error: Failed to read ETF token contract: {str(e)}" balance_info = { "chain": config.name, "chain_id": config.chain_id, "wallet_address": wallet_address, "etf_token_address": etf_token_address, "symbol": symbol, "balance": str(balance), "balance_wei": str(balance_wei), "decimals": decimals } return json.dumps(balance_info, indent=2) except Exception as e: logger.error(f"Error getting ETF balance: {e}") return f"Error getting ETF balance: {str(e)}"