code_at

Returns deployed bytecode for an address in live, pinned, or retained execution state. Without a CLIENT, it builds a reusable READ and does not access state.

Example

Local

1
SELECT code_at('0x0000000000000000000000000000000000000001'::ADDRESS);
Notebook ready in readonly mode.

API reference

Exact signatures with descriptions, requirements, inputs, returns, and examples.

code_at(CLIENT, ADDRESS) # Immediate Read · RPC required

Reads the CLIENT's current state context. For live clients that means latest; pinned and execution clients retain their own exact state identity.

Inputs

Name Type Use
client CLIENT

Readable EVM state represented by a live, pinned, or execution CLIENT.

required positional
address ADDRESS

Contract or account address whose code should be read.

required positional

Returns

Name Type
code BYTES

Deployed bytecode. Returns the deployed bytecode as BYTES, or NULL/empty code for EOAs, pre-deploy addresses, or historical blocks where no code existed. Historical reads may require an archive-capable RPC provider.

Guidance

Historical code

The two-argument overload reads latest and can change after upgrades, redeploys on new chains, or proxy changes in surrounding state.

Use block_number for reproducible bytecode evidence.

Relation-sized attached pinned reads may share one hash-pinned JSON-RPC batch; each inner request keeps the durable blockHash and requireCanonical selector.

Older block heights may require an archive node.

Additional overloads

code_at(CLIENT, ADDRESS, BIGINT) # Immediate Read · RPC required

Returns the deployed bytecode at a specific block height for reproducible historical replay.

Inputs

Name Type Use
client CLIENT

Readable EVM state represented by a live, pinned, or execution CLIENT.

required positional
address ADDRESS

Contract or account address whose code should be read.

required positional
block_number BIGINT

Optional historical block height.

required positional

Returns

Name Type
code BYTES

Deployed bytecode. Returns the deployed bytecode as BYTES, or NULL/empty code for EOAs, pre-deploy addresses, or historical blocks where no code existed. Historical reads may require an archive-capable RPC provider.

Overload examples

Named parameters · RPC required

1
SELECT code_at(
2
$client, -- client
3
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'::address, -- Ethereum mainnet WETH
4
21000000 -- Ethereum mainnet block_number
5
) AS code;
code_at(ADDRESS) # Read Builder · RPC required

Builds a reusable account-code READ; no client is resolved and no state is accessed.

Inputs

Name Type Use
address ADDRESS

Contract or account address whose deployed code should be observed.

required positional

Returns

Name Type
read READ

Account-code READ. Returns a canonical READ specification for a later account-code observation.

Examples

Named parameters · RPC required

1
SELECT code_at(
2
$client, -- client
3
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'::address -- Ethereum mainnet WETH
4
) AS code;
Notebook ready in readonly mode.

Related functions

Category and tags

Category
Chain reads
Tag
RPC
Tag
Simulate