eth_getBlockByNumber
根据区块号返回区块信息。
QUANTITY|TAG— 区块号,或字符串"earliest"、"latest"、"safe"、"finalized"、"pending"。Boolean—true返回完整交易对象,false仅返回交易哈希列表。
Object|null — 区块对象;查不到时返回 null。
| 字段 | 类型 | 说明 |
|---|---|---|
| number | QUANTITY | 区块号 |
| hash | DATA | 区块哈希 |
| parentHash | DATA | 父区块哈希 |
| timestamp | QUANTITY | Unix 时间戳 |
| gasUsed | QUANTITY | 已使用 Gas |
| gasLimit | QUANTITY | Gas 上限 |
| baseFeePerGas | QUANTITY | 基础费(EIP-1559) |
| transactions | Array | 交易哈希或交易对象 |
curl -X POST https://eth-mainnet.blockreq.com/v1/rpc/public \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "eth_getBlockByNumber", "params": ["latest", false], "id": 1 }'{ "jsonrpc": "2.0", "id": 1, "result": { "number": "0x134e82a", "hash": "0xabc...def", "parentHash": "0x123...456", "timestamp": "0x65a1b2c3", "gasUsed": "0x1234", "gasLimit": "0x1c9c380", "baseFeePerGas": "0x3b9aca00", "transactions": ["0x..."] }}JavaScript (ethers.js v6)
Section titled “JavaScript (ethers.js v6)”import { JsonRpcProvider } from "ethers";const provider = new JsonRpcProvider("https://eth-mainnet.blockreq.com/v1/rpc/YOUR_API_KEY");const block = await provider.getBlock("latest");console.log("Block:", block.number, "Txs:", block.transactions.length);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"))block = w3.eth.get_block("latest")print(f"Block {block.number} — {len(block.transactions)} txs")| Method | Cost |
|---|---|
| eth_getBlockByNumber | 10 RU |