Skip to main content
Glama

get_pusd_balance

Retrieve PUSD token balance information for a specified blockchain chain ID. Returns JSON data showing current balance on supported EVM chains.

Instructions

Get PUSD token balance on specified chain.

Args:
    chain_id: Chain ID (1, 10, 56, 100, 137, 8453, 42161)

Returns:
    JSON string with PUSD balance information.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chain_idYes

Implementation Reference

  • The handler function that implements the get_pusd_balance tool. It retrieves the PUSD token balance for the server's account on the specified EVM chain by querying the ERC20 contract using Web3.py.
    async def get_pusd_balance(ctx: Context, chain_id: str) -> str:
        """Get PUSD token balance on specified chain.
        
        Args:
            chain_id: Chain ID (1, 10, 56, 100, 137, 8453, 42161)
        
        Returns:
            JSON string with PUSD 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]
            if not config.pusd_token:
                return f"Error: PUSD token address not configured for {config.name}"
            
            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]
            pusd_contract = web3.eth.contract(
                address=config.pusd_token,
                abi=ERC20_ABI
            )
            
            balance_wei = pusd_contract.functions.balanceOf(paloma_ctx.address).call()
            decimals = pusd_contract.functions.decimals().call()
            balance = balance_wei / (10 ** decimals)
            
            balance_info = {
                "chain": config.name,
                "chain_id": config.chain_id,
                "token_address": config.pusd_token,
                "balance": str(balance),
                "symbol": "PUSD",
                "decimals": decimals
            }
            
            return json.dumps(balance_info, indent=2)
            
        except Exception as e:
            logger.error(f"Error getting PUSD balance: {e}")
            return f"Error getting PUSD balance: {str(e)}"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/VolumeFi/mcpPADEX'

If you have feedback or need assistance with the MCP directory API, please join our Discord server