← 返回
开发者工具 Key 中文

Etherscan

Query EVM chain data via Etherscan API v2. Use for on-chain lookups where Etherscan v2 applies: balances, transactions, token transfers (ERC-20/721/1155), co...
通过 Etherscan API v2 查询 EVM 链数据。适用于 Etherscan v2 支持的链上查询:余额、交易、代币转账(ERC-20/721/1155)等。
0xv4l3nt1n3
开发者工具 clawhub v1.0.0 1 版本 100000 Key: 需要
★ 0
Stars
📥 654
下载
💾 2
安装
1
版本
#latest

概述

Etherscan (API v2)

Your job: Query EVM chains without guessing. Wrong module/action = empty results. Wrong chain = silent failure.

-----------------------------------------------------------------
Base URLhttps://api.etherscan.io/v2/api
Auth?apikey={key} query param
Rate limit~5/second (free tier). Exceed → message=NOTOK
CitationEnd with "Powered by Etherscan" — required.

Step 0: Get API Key (If Needed)

Try sources in order:

  1. Credentials file~/.config/etherscan/credentials.json{"api_key":"..."}
  2. Environment variable$ETHERSCAN_API_KEY
  3. Ask user (last resort) — acknowledge receipt, don't echo it

No key? → https://etherscan.io/apidashboard (register, generate free key)

Save it:

mkdir -p ~/.config/etherscan
cat > ~/.config/etherscan/credentials.json << 'EOF'
{"api_key":"USER_KEY_HERE"}
EOF
chmod 600 ~/.config/etherscan/credentials.json

Step 1: Fetch Chain List (REQUIRED, once per session)

Do NOT hardcode chain IDs. Fetch and cache on first call:

curl -s "https://api.etherscan.io/v2/chainlist"

Returns chain map: {"result": [{"chainid": "1", "name": "Ethereum Mainnet"}, ...]}. Map user's chain name → chainid. If ambiguous, ask. Never assume default.

Refresh when: session start, cache miss, user says "refresh", or >24hr stale.


Pick Your Endpoint

Wrong module/action wastes a call. Match the task:

You needmoduleactionKey params
--------------------------------------------------------------------------------------------------
Native balanceaccountbalanceaddress, tag=latest
Multi-address balanceaccountbalancemultiaddress (comma-sep, max 20)
Normal transactionsaccounttxlistaddress, page, offset, sort=desc
Internal transactionsaccounttxlistinternaladdress or txhash
ERC-20 transfersaccounttokentxaddress, optional contractaddress
ERC-721 transfersaccounttokennfttxaddress
ERC-1155 transfersaccounttoken1155txaddress
ERC-20 token balanceaccounttokenbalancecontractaddress, address
Contract ABIcontractgetabiaddress (verified only)
Contract sourcecontractgetsourcecodeaddress
Contract creatorcontractgetcontractcreationcontractaddresses (comma-sep)
Gas pricesgastrackergasoracle
Tx receipt statustransactiongettxreceiptstatustxhash
Event logslogsgetLogsaddress, fromBlock, toBlock, topics
Latest blockproxyeth_blockNumber
Tx by hashproxyeth_getTransactionByHashtxhash
Full receiptproxyeth_getTransactionReceipttxhash

Format: GET https://api.etherscan.io/v2/api?module={module}&action={action}&chainid={chainid}&apikey={key}&{params}


Common Tokens

Don't guess addresses. Use these:

TokenChainDecimalsAddress
-------------------------------------------------------------------
WETHEthereum180xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
USDCEthereum60xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
USDTEthereum60xdAC17F958D2ee523a2206206994597C13D831ec7
DAIEthereum180x6B175474E89094C44Da98b954EedeAC495271d0F
WBTCEthereum80x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599
WBNBBSC180xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c
USDCBSC180x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d
WMATICPolygon180x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270
USDCPolygon60x3c499c542cEF5E3811e1192ce70d8cC03d5c3359
WETHArbitrum180x82aF49447D8a07e3bd95BD0d56f35241523fBab1
USDCArbitrum60xaf88d065e77c8cC2239327C5EDb3A432268e5831
ARBArbitrum180x912CE59144191C1204E64559FE8253a0e49E6548
WETHBase180x4200000000000000000000000000000000000006
USDCBase60x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
WETHOptimism180x4200000000000000000000000000000000000006
USDCOptimism60x0b2C639c533813f4Aa9D7837CAf62653d097Ff85
OPOptimism180x4200000000000000000000000000000000000042

Native tokens (ETH, BNB, MATIC): Use module=account&action=balance, no contract address.


Quick Examples

Check ETH Balance

curl -s "https://api.etherscan.io/v2/api?module=account&action=balance&address=0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb&chainid=1&tag=latest&apikey=${API_KEY}"

Get Recent Transactions

curl -s "https://api.etherscan.io/v2/api?module=account&action=txlist&address=0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb&chainid=1&page=1&offset=10&sort=desc&apikey=${API_KEY}"

Check USDC Balance

curl -s "https://api.etherscan.io/v2/api?module=account&action=tokenbalance&contractaddress=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48&address=0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb&chainid=1&tag=latest&apikey=${API_KEY}"
# Returns raw integer — divide by 10^6 for USDC

Verify Transaction Status

curl -s "https://api.etherscan.io/v2/api?module=transaction&action=gettxreceiptstatus&txhash=0xABC...&chainid=1&apikey=${API_KEY}"
# result.status = "1" → success, "0" → failed

Get Current Gas Prices

curl -s "https://api.etherscan.io/v2/api?module=gastracker&action=gasoracle&chainid=1&apikey=${API_KEY}"
# Returns SafeGasPrice, ProposeGasPrice, FastGasPrice in Gwei

Critical Rules

Pagination: Always include page=1&offset=100&sort=desc on list endpoints. For "all" results, paginate until result.length < offset.

Token balances: Returned as raw integers. Divide by 10^decimals.

Time filtering: Most endpoints lack server-side time filters. Fetch results, filter by timeStamp client-side.

Errors:

  • status=0, empty result → wrong chain or action
  • message=NOTOK → rate limit or invalid params
  • Missing recent txs → forgot pagination params

Transaction verification: Never assume finality. Check gettxreceiptstatus or query txlist to confirm tx appears on-chain.


References

Full docs: https://docs.etherscan.io/llms.txt

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-30 09:29 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

developer-tools

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 68 📥 180,474
developer-tools

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 672 📥 324,534
developer-tools

Gog

steipete
Google Workspace 命令行工具,支持 Gmail、日历、云端硬盘、通讯录、表格和文档。
★ 921 📥 185,927