eth_getCode
Returns code at a given address. Used to check if an address is a smart contract.
Parameters
Section titled “Parameters”DATA(20 bytes) — Address to get code from.QUANTITY|TAG— Block number, or"latest","earliest","pending".
Returns
Section titled “Returns”DATA — The code from the given address. Returns 0x for EOA (non-contract) accounts.
Request
Section titled “Request”# Check USDC contractcurl -X POST https://eth-mainnet.blockreq.com/v1/rpc/public \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "eth_getCode", "params": ["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "latest"], "id": 1 }'Response
Section titled “Response”{ "jsonrpc": "2.0", "id": 1, "result": "0x6080604052..."}If the result is
"0x", the address is an EOA (externally owned account), not a contract.
Code Examples
Section titled “Code Examples”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 code = await provider.getCode("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48");console.log("Is contract:", code !== "0x");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"))code = w3.eth.get_code("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48")print(f"Is contract: {len(code) > 0}")RU Cost
Section titled “RU Cost”| Method | Cost |
|---|---|
| eth_getCode | 10 RU |