Skip to main content
Glama
blockscout

Blockscout MCP Server

Official

get_tokens_by_address

Read-only

Retrieve ERC20 token holdings for a blockchain address with metadata and market data for portfolio analysis, wallet auditing, and DeFi tracking.

Instructions

Get comprehensive ERC20 token holdings for an address with enriched metadata and market data.
Returns detailed token information including contract details (name, symbol, decimals), market metrics (exchange rate, market cap, volume), holders count, and actual balance (provided as is, without adjusting by decimals).
Essential for portfolio analysis, wallet auditing, and DeFi position tracking.
**SUPPORTS PAGINATION**: If response includes 'pagination' field, use the provided next_call to get additional pages.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chain_idYesThe ID of the blockchain
addressYesWallet address
cursorNoThe pagination cursor from a previous response to get the next page of results.

Implementation Reference

  • Core handler function implementing the get_tokens_by_address tool. Fetches ERC20 tokens for an address via Blockscout API, processes into TokenHoldingData, handles pagination with cursor, and returns ToolResponse.
    @log_tool_invocation
    async def get_tokens_by_address(
        chain_id: Annotated[str, Field(description="The ID of the blockchain")],
        address: Annotated[str, Field(description="Wallet address")],
        ctx: Context,
        cursor: Annotated[
            str | None,
            Field(description="The pagination cursor from a previous response to get the next page of results."),
        ] = None,
    ) -> ToolResponse[list[TokenHoldingData]]:
        """
        Get comprehensive ERC20 token holdings for an address with enriched metadata and market data.
        Returns detailed token information including contract details (name, symbol, decimals), market metrics (exchange rate, market cap, volume), holders count, and actual balance (provided as is, without adjusting by decimals).
        Essential for portfolio analysis, wallet auditing, and DeFi position tracking.
        **SUPPORTS PAGINATION**: If response includes 'pagination' field, use the provided next_call to get additional pages.
        """  # noqa: E501
        api_path = f"/api/v2/addresses/{address}/tokens"
        params = {"type": "ERC-20"}
    
        # Add pagination parameters if provided via cursor
        apply_cursor_to_params(cursor, params)
    
        # Report start of operation
        await report_and_log_progress(
            ctx, progress=0.0, total=2.0, message=f"Starting to fetch token holdings for {address} on chain {chain_id}..."
        )
    
        base_url = await get_blockscout_base_url(chain_id)
    
        # Report progress after resolving Blockscout URL
        await report_and_log_progress(
            ctx, progress=1.0, total=2.0, message="Resolved Blockscout instance URL. Fetching token data..."
        )
    
        response_data = await make_blockscout_request(base_url=base_url, api_path=api_path, params=params)
    
        # Report completion
        await report_and_log_progress(ctx, progress=2.0, total=2.0, message="Successfully fetched token data.")
    
        items_data = response_data.get("items", [])
        token_holdings = []
        for item in items_data:
            # To preserve the LLM context, only specific fields are added to the response
            token = item.get("token", {})
            decimals_value = token.get("decimals")
            total_supply_value = token.get("total_supply")
            circulating_market_cap_value = token.get("circulating_market_cap")
            exchange_rate_value = token.get("exchange_rate")
            holders_count_value = token.get("holders_count")
            balance_value = item.get("value")
            token_holdings.append(
                TokenHoldingData(
                    address=token.get("address_hash", ""),
                    name=token.get("name") or "",
                    symbol=token.get("symbol") or "",
                    decimals="" if decimals_value is None else str(decimals_value),
                    total_supply="" if total_supply_value is None else str(total_supply_value),
                    circulating_market_cap=(
                        None if circulating_market_cap_value is None else str(circulating_market_cap_value)
                    ),
                    exchange_rate=None if exchange_rate_value is None else str(exchange_rate_value),
                    holders_count="" if holders_count_value is None else str(holders_count_value),
                    balance="" if balance_value is None else str(balance_value),
                )
            )
    
        # Since there could be more than one page of tokens for the same address,
        # the pagination information is extracted from API response and added explicitly
        # to the tool response
        pagination = None
        next_page_params = response_data.get("next_page_params")
        if next_page_params:
            next_cursor = encode_cursor(next_page_params)
            pagination = PaginationInfo(
                next_call=NextCallInfo(
                    tool_name="get_tokens_by_address",
                    params={
                        "chain_id": chain_id,
                        "address": address,
                        "cursor": next_cursor,
                    },
                )
            )
    
        return build_tool_response(data=token_holdings, pagination=pagination)
  • Pydantic model defining the structure of each token holding returned by the tool.
    # --- Model for get_tokens_by_address Data Payload ---
    class TokenHoldingData(BaseModel):
        """Represents a single token holding with its associated metadata."""
    
        address: str = Field(description="The contract address of the token.")
        name: str = Field(description="The full name of the token (e.g., 'USD Coin').")
        symbol: str = Field(description="The symbol of the token (e.g., 'USDC').")
        decimals: str = Field(description="The number of decimals the token uses.")
        total_supply: str = Field(description="The total supply of the token.")
        circulating_market_cap: str | None = Field(description="The circulating market cap, if available.")
        exchange_rate: str | None = Field(description="The current exchange rate, if available.")
        holders_count: str = Field(description="The number of addresses holding this token.")
        balance: str = Field(description="The token balance for the queried address (unadjusted for decimals).")
  • Registration of the get_tokens_by_address tool with the FastMCP server instance.
    mcp.tool(
        structured_output=False,
        annotations=create_tool_annotations("Get Tokens by Address"),
    )(get_tokens_by_address)
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint=true and destructiveHint=false, indicating a safe read operation. The description adds valuable behavioral context: it discloses pagination support with instructions on using the 'next_call', specifies that balance is provided 'as is, without adjusting by decimals', and mentions enriched metadata and market data. This goes beyond annotations without contradiction.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and front-loaded with the core purpose in the first sentence. Each subsequent sentence adds value: details on return data, use cases, and pagination instructions. There is no wasted text, and it efficiently conveys necessary information in four concise sentences.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no output schema, the description compensates by detailing return values: 'contract details (name, symbol, decimals), market metrics (exchange rate, market cap, volume), holders count, and actual balance'. It also covers pagination behavior. However, it lacks error handling or rate limit information, which could be useful given the openWorldHint annotation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents parameters (chain_id, address, cursor). The description adds no specific parameter semantics beyond what the schema provides, such as format examples or constraints for 'address' or 'chain_id'. Baseline 3 is appropriate when schema handles parameter documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Get' and resource 'ERC20 token holdings for an address' with specific scope 'comprehensive...with enriched metadata and market data'. It distinguishes from siblings like 'nft_tokens_by_address' (NFTs vs ERC20) and 'get_token_transfers_by_address' (transfers vs holdings).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly states use cases: 'portfolio analysis, wallet auditing, and DeFi position tracking', providing clear context for when to use this tool. However, it does not mention when not to use it or name specific alternatives among siblings, such as 'nft_tokens_by_address' for NFTs instead of ERC20 tokens.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/blockscout/mcp-server'

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