Accounts & state2 CU

eth_getCode on Optimism

Returns the deployed bytecode at an address. An empty result (0x) means the address is an EOA, not a contract — a common way to distinguish the two.

The canonical EOA-vs-contract test: non-empty bytecode almost always means a contract. It returns 0x for a contract not yet deployed at that block, and for EIP-7702-delegated EOAs you'll see a short delegation indicator rather than full code.

Optimism endpoint (public — no key)

https://rpc.nodeflare.app/op/public

Method

eth_getCode

Cost

2 CU

Chain ID

10

Block time

~2 s

Finality

~2 s soft · L1-final ~13 min

Accounts & state on Optimism

State reads behave as on Ethereum. The regenesis history (pre-Bedrock, Nov 2021–Jun 2023) means very old state may not be reachable the way recent state is.

Parameters

[address, blockNumber|tag]

cURL

curl https://rpc.nodeflare.app/op/public \
  -X POST \
  -H 'content-type: application/json' \
  -d '{"jsonrpc":"2.0","method":"eth_getCode","params":["0x0b2c639c533813f4aa9d7837caf62653d097ff85", "latest"],"id":1}'

The example targets the USDC contract on Optimism — you can run it as-is.

ethers.js

import { ethers } from 'ethers';

const provider = new ethers.JsonRpcProvider(
  'https://rpc.nodeflare.app/op/public'
);

const result = await provider.send('eth_getCode', ["0x0b2c639c533813f4aa9d7837caf62653d097ff85", "latest"]);

Try it live

Runs the example above against the public Optimism endpoint — straight from your browser.

eth_getCode on Optimism — FAQ

How do I call eth_getCode on Optimism?

POST a JSON-RPC 2.0 request with "method": "eth_getCode" to NodeFlare's Optimism endpoint at https://rpc.nodeflare.app/op/public. No API key is required for the public endpoint.

What does eth_getCode cost on the free tier?

eth_getCode is weighted at 2 compute units per call. The free tier includes 2,000,000 CU/month, so that is roughly 1,000,000 eth_getCode calls per month — no credit card.

Is eth_getCode available on the public Optimism endpoint?

Yes. eth_getCode works on the public Optimism endpoint (https://rpc.nodeflare.app/op/public) with no API key, rate-limited per IP. A free key adds higher limits and a dedicated path.

Anything Optimism-specific to know when using eth_getCode?

State reads behave as on Ethereum. The regenesis history (pre-Bedrock, Nov 2021–Jun 2023) means very old state may not be reachable the way recent state is.

Call eth_getCode on Optimism with a free key

2,000,000 compute units/month, heavy methods unlocked, every chain included. No credit card.

Get your free API key →