eth_getBalance
返回指定地址账户余额。
DATA(20 字节)— 要查询余额的地址。QUANTITY|TAG— 区块号,或"latest"、"earliest"、"pending"。
QUANTITY — 当前余额(单位 wei)。
curl -X POST https://eth-mainnet.blockreq.com/v1/rpc/public \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "eth_getBalance", "params": ["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "latest"], "id": 1 }'{ "jsonrpc": "2.0", "id": 1, "result": "0x6c6b935b8bbd400000"}返回值单位为 wei。
0x6c6b935b8bbd400000= 2000 ETH。
JavaScript (ethers.js v6)
Section titled “JavaScript (ethers.js v6)”import { JsonRpcProvider, formatEther } from "ethers";const provider = new JsonRpcProvider("https://eth-mainnet.blockreq.com/v1/rpc/YOUR_API_KEY");const balance = await provider.getBalance("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045");console.log("Balance:", formatEther(balance), "ETH");Python (web3.py)
Section titled “Python (web3.py)”from web3 import Web3w3 = Web3(Web3.HTTPProvider("https://eth-mainnet.blockreq.com/v1/rpc/YOUR_API_KEY"))balance = w3.eth.get_balance("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045")print(f"Balance: {w3.from_wei(balance, 'ether')} ETH")| Method | Cost |
|---|---|
| eth_getBalance | 10 RU |