Skip to main content
Glama
blockscout

Blockscout MCP Server

Official

get_contract_abi

Retrieve smart contract ABIs to format function calls and interpret blockchain data, enabling interaction with contracts on supported chains.

Instructions

Get smart contract ABI (Application Binary Interface). An ABI defines all functions, events, their parameters, and return types. The ABI is required to format function calls or interpret contract data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chain_idYesThe ID of the blockchain
addressYesSmart contract address

Implementation Reference

  • The core handler function that fetches the smart contract ABI from the Blockscout API using the provided chain_id and address. It reports progress, makes the API request, extracts the ABI, and returns a standardized ToolResponse.
    @log_tool_invocation async def get_contract_abi( chain_id: Annotated[str, Field(description="The ID of the blockchain")], address: Annotated[str, Field(description="Smart contract address")], ctx: Context, ) -> ToolResponse[ContractAbiData]: """ Get smart contract ABI (Application Binary Interface). An ABI defines all functions, events, their parameters, and return types. The ABI is required to format function calls or interpret contract data. """ # noqa: E501 api_path = f"/api/v2/smart-contracts/{address}" # Report start of operation await report_and_log_progress( ctx, progress=0.0, total=2.0, message=f"Starting to fetch contract ABI 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 contract ABI...", ) response_data = await make_blockscout_request(base_url=base_url, api_path=api_path) # Report completion await report_and_log_progress( ctx, progress=2.0, total=2.0, message="Successfully fetched contract ABI.", ) # Extract the ABI from the API response as it is abi_data = ContractAbiData(abi=response_data.get("abi")) return build_tool_response(data=abi_data)
  • Pydantic model defining the output data structure for the get_contract_abi tool, containing the ABI as a list of dictionaries.
    # --- Model for get_contract_abi Data Payload --- class ContractAbiData(BaseModel): """A structured representation of a smart contract's ABI.""" abi: list[dict[str, Any]] | None = Field( description="The Application Binary Interface (ABI) of the smart contract." )
  • MCP server registration of the get_contract_abi tool, including annotations for title, readOnlyHint, etc.
    mcp.tool( structured_output=False, annotations=create_tool_annotations("Get Contract ABI"), )(get_contract_abi)

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