Optimism
Optimism
Optimism
免费套餐涵盖个人项目。按量付费,无需绑卡即可扩展。
eth_getBalance returns the ETH balance of an account on OP Mainnet at a specified block — ETH is the native gas token of this OP Stack rollup. The value comes back as hex-encoded wei, so it reflects the bridged ETH an address holds on L2, not on Ethereum L1. Query https://optimism.therpc.io/YOUR_API_KEY (chain ID 10, 0xa) with an address and a block tag such as latest or finalized.
latest to detect incoming ETH payments on the rollup as blocks land every ~2 seconds.| # | 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|---|
| 1 | address | string (hex) | 是 | The account address to query. |
| 2 | blockTag | string | 否 | Block at which to read the balance.默认值: latest |
| 类型 | 描述 |
|---|---|
| string (hex) | Hex-encoded balance in wei. Convert with BigInt(value); divide by 10n**18n to get the chain's base unit. |
Try it live in the Optimism playground.
| 错误码 | 错误信息 | 原因 |
|---|---|---|
-32602 | Invalid params | Address is malformed, missing 0x prefix, or block tag is unrecognised. |
-32000 | Missing trie node | Queried a historical block that the node has pruned (non-archive node). |
Number() — an OP Mainnet balance above 2^53 wei loses precision; always use BigInt(value) and divide by 10n**18n for whole ETH.latest reflects unfinalized L2 state; for a system of record that must survive a reorg before L1 settlement, read at finalized instead.eth_call the token contract's balanceOf.参数
0x-prefixed 20-byte address
hex block number or "latest"/"earliest"/"pending"/"safe"/"finalized"