etherscan-mcp-python

FLock-io/etherscan-mcp-python

3.3

If you are the rightful owner of etherscan-mcp-python and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The Etherscan MCP Python Server is a comprehensive solution for accessing Ethereum blockchain data through the Etherscan API, implemented using the Model Context Protocol (MCP).

Tools
  1. account_balance

    Get ETH balance for a single address.

  2. block_getblockreward

    Get block mining reward and uncle rewards.

  3. contract_getabi

    Get contract ABI for verified contracts.

Etherscan MCP Python Server

A complete Python implementation of the Etherscan Model Context Protocol (MCP) server, providing comprehensive access to Ethereum blockchain data through the Etherscan API.

Overview

This server provides 53+ tools for accessing Ethereum blockchain data, including:

  • Account Tools: Balance checking, transaction history, internal transactions
  • Block Tools: Block data, rewards, timing information
  • Contract Tools: Source code, ABI, verification status
  • Transaction Tools: Transaction details, receipts, status
  • Token Tools: Transfers, balances, supply information
  • Gas Tools: Gas prices, estimates, oracle data
  • Statistics Tools: Network metrics, supply data
  • RPC Tools: Ethereum RPC proxy methods
  • Logs Tools: Event logs and filtering

Requirements

  • Python 3.8+
  • Etherscan API Key

Installation

cd etherscan-mcp-python
pip install -e .

Configuration

Set your Etherscan API key as an environment variable:

export ETHERSCAN_API_KEY="your_api_key_here"

Usage

Standalone Server

python server.py

With MCP Tools (Agno Framework)

from agno.tools.mcp import MCPTools

etherscan_mcp = MCPTools(
    command="python etherscan-mcp-python/server.py",
    env={"ETHERSCAN_API_KEY": "your_api_key"},
    timeout_seconds=120
)

Complete Tool Reference

🏦 Account Tools (12 tools)

Tool NameDescriptionKey Parameters
account_balanceGet ETH balance for single addressaddress, chainid
account_balancemultiGet ETH balance for multiple addresses (up to 20)address (comma-separated), chainid
account_txlistGet normal transactions by addressaddress, startblock, endblock, page, offset
account_txlistinternalGet internal transactions by addressaddress, startblock, endblock, page, offset
account_txlistinternal_byhashGet internal transactions by transaction hashtxhash, chainid
account_txlistinternal_byblockGet internal transactions by block rangestartblock, endblock, page, offset
account_tokentxGet ERC20 token transfer eventsaddress, contractaddress, startblock, endblock
account_tokennfttxGet ERC721 (NFT) token transfer eventsaddress, contractaddress, startblock, endblock
account_token1155txGet ERC1155 token transfer eventsaddress, contractaddress, startblock, endblock
account_fundedbyGet address funding source and ageaddress, chainid
account_getminedblocksGet blocks validated by addressaddress, blocktype, page, offset
account_txsBeaconWithdrawalGet beacon chain withdrawalsaddress, startblock, endblock, page, offset

🧱 Block Tools (4 tools)

Tool NameDescriptionKey Parameters
block_getblockrewardGet block mining reward and uncle rewardsblockno, chainid
block_getblockcountdownGet estimated time until block is minedblockno, chainid
block_getblocknobytimeGet block number by timestamptimestamp, closest, chainid
block_getblocktxnscountGet number of transactions in blockblockno, chainid

📄 Contract Tools (4 tools)

Tool NameDescriptionKey Parameters
contract_getabiGet contract ABI for verified contractsaddress, chainid
contract_getsourcecodeGet verified contract source codeaddress, chainid
contract_getcontractcreationGet contract creator and creation tx hashcontractaddresses, chainid
contract_checkverifystatusCheck contract verification statusguid, chainid

🔄 Transaction Tools (2 tools)

Tool NameDescriptionKey Parameters
transaction_getstatusGet contract execution statustxhash, chainid
transaction_gettxreceiptstatusGet transaction receipt statustxhash, chainid

🪙 Token Tools (2 tools)

Tool NameDescriptionKey Parameters
stats_tokensupplyGet ERC20 token total supplycontractaddress, chainid
account_tokenbalanceGet ERC20 token balance of addresscontractaddress, address, chainid

⛽ Gas Tools (3 tools)

Tool NameDescriptionKey Parameters
gas_gasestimateGet estimated confirmation time for gas pricegasprice, chainid
gas_gasoracleGet current safe/proposed/fast gas priceschainid
stats_dailyavggaslimitGet historical daily average gas limitstartdate, enddate, sort, chainid

📊 Statistics Tools (13 tools)

Tool NameDescriptionKey Parameters
stats_ethsupplyGet total ETH supply (excluding staking/burnt)chainid
stats_ethsupply2Get total ETH supply (including staking/burnt)chainid
stats_ethpriceGet current ETH pricechainid
stats_chainsizeGet blockchain size over date rangestartdate, enddate, clienttype, syncmode
stats_nodecountGet total discoverable nodeschainid
stats_dailytxnfeeGet daily transaction fees paid to minersstartdate, enddate, sort
stats_dailynewaddressGet daily new address countstartdate, enddate, sort
stats_dailynetutilizationGet daily network utilization percentagestartdate, enddate, sort
stats_dailyavghashrateGet daily average network hash ratestartdate, enddate, sort
stats_dailytxGet daily transaction countstartdate, enddate, sort
stats_dailyavgnetdifficultyGet daily average mining difficultystartdate, enddate, sort
stats_ethdailypriceGet historical ETH pricesstartdate, enddate, sort

📝 Logs Tools (3 tools)

Tool NameDescriptionKey Parameters
logs_getLogsByAddressGet event logs from address with block rangeaddress, fromBlock, toBlock, page, offset
logs_getLogsByTopicsGet event logs filtered by topicsfromBlock, toBlock, topic0-3, operators
logs_getLogsByAddressAndTopicsGet event logs from address filtered by topicsaddress, fromBlock, toBlock, topic0-3

🔗 RPC Proxy Tools (13 tools)

Tool NameDescriptionKey Parameters
proxy_eth_blockNumberGet latest block numberchainid
proxy_eth_getBlockByNumberGet block information by numbertag, boolean, chainid
proxy_eth_getUncleByBlockNumberAndIndexGet uncle block by number and indextag, index, chainid
proxy_eth_getBlockTransactionCountByNumberGet transaction count in blocktag, chainid
proxy_eth_getTransactionByHashGet transaction by hashtxhash, chainid
proxy_eth_getTransactionByBlockNumberAndIndexGet transaction by block and indextag, index, chainid
proxy_eth_getTransactionCountGet transaction count by addressaddress, tag, chainid
proxy_eth_getTransactionReceiptGet transaction receipttxhash, chainid
proxy_eth_callExecute message call without transactionto, data, tag, chainid
proxy_eth_getCodeGet code at addressaddress, tag, chainid
proxy_eth_getStorageAtGet storage value at positionaddress, position, tag, chainid
proxy_eth_gasPriceGet current gas pricechainid
proxy_eth_estimateGasEstimate gas for transactiondata, to, value, gas, gasPrice

🎯 Use Cases & Examples

Basic Balance Check

# Get ETH balance for single address
account_balance(address="0x...", chainid="1")

# Get balances for multiple addresses (up to 20)
account_balancemulti(address="0x...,0x...,0x...", chainid="1")

Transaction Analysis

# Get transaction history for address
account_txlist(address="0x...", startblock="0", endblock="99999999")

# Get internal transactions (contract interactions)
account_txlistinternal(address="0x...", page="1", offset="100")

Block Information

# Get transaction count in specific block (like the web3_GAIA_test.py example)
block_getblocktxnscount(blockno="17000000", chainid="1")

# Get block mining rewards
block_getblockreward(blockno="17000000", chainid="1")

Market Data

# Get current ETH price
stats_ethprice(chainid="1")

# Get current gas prices
gas_gasoracle(chainid="1")

Smart Contract Analysis

# Get contract source code (if verified)
contract_getsourcecode(address="0x...", chainid="1")

# Get contract ABI
contract_getabi(address="0x...", chainid="1")

🔧 Advanced Configuration

Multi-Chain Support

The server supports multiple Ethereum networks via the chainid parameter:

  • "1" - Ethereum Mainnet (default)
  • "5" - Goerli Testnet
  • "11155111" - Sepolia Testnet
  • And other supported networks

Error Handling

The server includes comprehensive error handling for:

  • ❌ Missing API keys
  • ❌ Invalid parameters
  • ❌ API rate limits
  • ❌ Network timeouts
  • ❌ Malformed responses

Performance Optimization

  • ✅ Synchronous HTTP client for MCP compatibility
  • ✅ Efficient JSON parsing and response formatting
  • ✅ Proper timeout handling (120 seconds default)
  • ✅ Memory-efficient tool registration

🔐 Security & Best Practices

API Key Management

  • Store ETHERSCAN_API_KEY in environment variables
  • Never commit API keys to version control
  • Use .env files for local development
  • Rotate API keys regularly

Rate Limiting

  • Etherscan API has rate limits (free tier: 5 calls/sec)
  • The server respects these limits
  • Consider upgrading to Etherscan Pro for higher limits

Data Validation

  • All input parameters are validated
  • API responses are checked for errors
  • Malformed data is handled gracefully

🆘 Troubleshooting

Common Issues

❌ "ETHERSCAN_API_KEY not set"

  • Solution: Set the environment variable export ETHERSCAN_API_KEY="your_key"

❌ "Connection closed" or "Runtime error"

  • Solution: Ensure you're not running in nested async context
  • Check that the server.py uses synchronous main() function

❌ "Tool not found"

  • Solution: Verify tool names use underscores (account_balance not account/balance)
  • Check that tool renaming for Gemini compatibility is applied

❌ "Timeout after 120 seconds"

  • Solution: Check internet connectivity and API key validity
  • Verify Etherscan API is not experiencing outages

Debug Mode

For debugging, you can modify the server to add verbose logging:

import logging
logging.basicConfig(level=logging.DEBUG)

🤝 Contributing

Adding New Tools

  1. Choose appropriate tool category file (src/tools/)
  2. Follow existing patterns for parameter validation
  3. Add comprehensive docstrings
  4. Test with actual API calls
  5. Update this README with new tool documentation