View this page as Markdown

code_at

Reads an account's runtime bytecode from live RPC state, the exact state identified by a pinned CLIENT, or retained execution state. Without a CLIENT, it builds a reusable READ and does not access state.

Example

Local

SELECT code_at('0x0000000000000000000000000000000000000001'::ADDRESS);

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 retained execution CLIENT.

required positional
address ADDRESS

Account address whose runtime bytecode should be read.

required positional

Returns

Name Type
code BYTES

Deployed bytecode. Returns runtime bytecode as BYTES. A live RPC no-code response is NULL; pinned and execution state represent known no-code as empty BYTES. NULL or empty client, NULL address, and live RPC/decoding failures return NULL. Historical live reads and pinned-state hydration may require archive access.

Guidance

Historical code

The two-argument overload reads latest from a live CLIENT, so its result can change between runs.

Use block_number for reproducible bytecode evidence. Older heights may require an archive-capable provider.

Relation-sized attached pinned reads may share one hash-pinned JSON-RPC batch; each request retains the CLIENT's block hash and canonicality requirement.

State selection

An explicit block number is valid only for a live CLIENT. Supplying one for pinned or execution state raises STATE_SOURCE_INCONSISTENT.

Pinned reads use the CLIENT's block hash and canonicality requirement. An inconsistent identity or provider result raises STATE_SOURCE_INCONSISTENT.

Hydration and retained state

A detached pinned CLIENT can use retained state only; a cache miss raises HYDRATION_UNAVAILABLE. Attached pinned hydration can also raise HYDRATION_UNAVAILABLE when its provider cannot be reached.

Pinned hydration reports HISTORICAL_STATE_UNAVAILABLE when the provider does not retain the required state.

Execution reads use retained execution state and raise CHECKPOINT_UNAVAILABLE when that state cannot be resolved.

Evaluation

The READ accesses state only when an OBSERVATION consumes it during PROGRAM execution.

Additional overloads

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

Reads runtime bytecode at an exact block height through a live CLIENT. Pinned and execution CLIENTs reject an explicit height because their state identity is already fixed.

Inputs

Name Type Use
client CLIENT

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

required positional
address ADDRESS

Account address whose runtime bytecode should be read.

required positional
block_number BIGINT

Optional historical height for a live CLIENT. NULL is equivalent to omitting the argument.

required positional

Returns

Name Type
code BYTES

Deployed bytecode. Returns runtime bytecode as BYTES. A live RPC no-code response is NULL; pinned and execution state represent known no-code as empty BYTES. NULL or empty client, NULL address, and live RPC/decoding failures return NULL. Historical live reads and pinned-state hydration may require archive access.

Overload examples

Named parameters · RPC required

SELECT code_at(
    $client, -- client
    '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'::address, -- Ethereum mainnet WETH
    21000000 -- Ethereum mainnet block number
) AS code;
code_at(ADDRESS) # Read Builder · RPC required

Records one address for a later account-code lookup; construction does not access state.

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 READ whose successful EVM_VALUE contains the account's runtime bytecode.

Examples

Named parameters · RPC required

SELECT code_at(
    $client, -- client
    '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'::address -- Ethereum mainnet WETH
) AS code;

Related functions

Category and tags

Category
Chain reads
Tag
RPC
Tag
Simulate