Ethereum
准备好在生产环境中调用了吗?
免费套餐涵盖个人项目。按量付费,无需绑卡即可扩展。
Ethereum
免费套餐涵盖个人项目。按量付费,无需绑卡即可扩展。
eth_getCode returns the EVM bytecode living at an address on Ethereum mainnet (chain ID 1), the network where every contract call and deployment is paid for in ETH. Pass an address and a block, and the node reads the codeHash recorded in that account's state and hands back the actual bytecode behind it. Externally owned accounts hold no code, so they answer 0x; a deployed contract answers with its full runtime bytecode. Point the call at https://ethereum.therpc.io/YOUR_API_KEY, and because the block argument is honoured, you can read the code as it stood at any height, not just the chain head.
0x answer means an EOA, anything longer means deployed code. Wallets gate "this is a smart contract" warnings on exactly this check.SELFDESTRUCTed at a given height by reading its code at that block and seeing 0x come back where bytecode used to be.| # | 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|---|
| 1 | address | string (hex) | 是 | The address to read code from. |
| 2 | blockTag | string | 否 | Block at which to read the code.默认值: latest |
| 类型 | 描述 |
|---|---|
| string (hex) | Hex-encoded EVM bytecode, or "0x" if the address is an EOA, the contract was self-destructed, or no code existed at that block. |
Try it live in the Ethereum playground.
| 错误码 | 错误信息 | 原因 |
|---|---|---|
-32602 | Invalid params | Address is malformed or block tag is unrecognised. |
-32000 | Missing trie node | Historical block has been pruned on a non-archive node. |
0x is ambiguous: a never-deployed EOA and a contract that already self-destructed look identical. To tell them apart you need history — read the code at an earlier block, or check whether the account ever had a non-empty codeHash.eth_getStorageAt first, then call eth_getCode on that address.-32000 missing-trie-node error instead of bytecode.参数
0x-prefixed 20-byte address
hex block number or "latest"/"earliest"/"pending"/"safe"/"finalized"