get_etf_balance
Check ETF token balance for any wallet address across multiple blockchain networks including Ethereum, Arbitrum, and Polygon. Retrieve token holdings data by specifying chain ID and token contract 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
| Name | Required | Description | Default |
|---|---|---|---|
| chain_id | Yes | ||
| etf_token_address | Yes | ||
| wallet_address | No |
Input Schema (JSON Schema)
{
"properties": {
"chain_id": {
"title": "Chain Id",
"type": "string"
},
"etf_token_address": {
"title": "Etf Token Address",
"type": "string"
},
"wallet_address": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Wallet Address"
}
},
"required": [
"chain_id",
"etf_token_address"
],
"type": "object"
}
Implementation Reference
- padex.py:1027-1092 (handler)The main handler function for the 'get_etf_balance' tool. It retrieves the balance of an ETF token for a given wallet address on a specified EVM chain using Web3.py and the ERC20 ABI. Returns formatted JSON with balance details. The @mcp.tool() decorator registers it as an MCP tool.@mcp.tool() 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)}"