eth_bytecode
Disassemble EVM bytecode, scrape its selectors, or read its solc metadata.
Instructions
Disassemble EVM bytecode, scrape its selectors, or read its solc metadata.
code is hex runtime bytecode. The trailing solc CBOR metadata is data, not
code, so it is excluded from both the disassembly and the selector scrape and
reported as metadata_offset instead.
action=disassemble -> {size, code_size, count, offset, instructions} with each
instruction {pc, opcode, name} plus push_data for PUSH1..PUSH32; an
unassigned byte has name null and unknown, and code ending mid-immediate
is flagged truncated. Output is capped at limit instructions, which adds
{truncated, next_offset} — page with offset, or pass limit=0 for all.
action=selectors -> {count, selectors, sites}: every PUSH4 the dispatcher then
compares (EQ, or GT/LT in solc's binary-search dispatcher), decoded rather
than grepped, so a PUSH4 pattern inside another push's immediate cannot
masquerade as one. sites gives the {selector, pc, op} of each comparison.
This is a heuristic on unstructured code: an ERC-165 interface id is a
PUSH4 compared with EQ and is indistinguishable from a selector here, and
an unconventional dispatcher may hide one. Feed the results to
abi_inspect's selectors map (or a 4-byte database) to name them.
action=metadata -> {present, offset, length, cbor, metadata} plus
solc_version and, when the hash is an IPFS CIDv0 multihash, ipfs_cid.
Code compiled with metadata stripped returns present=false, not an error.
Example: eth_bytecode("selectors", "0x6080...") -> selectors=["0xa9059cbb", "0x70a08231"].
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Contract bytecode as hex (0x prefix optional) — the DEPLOYED runtime code, as returned by eth_getCode. Creation bytecode also decodes, but its constructor carries the runtime code as an inline blob, so the tail disassembles as data. | |
| limit | No | action=disassemble only: how many instructions to return; 0 removes the cap and returns all of them. | |
| action | Yes | 'disassemble' decodes the code into instructions; 'selectors' scrapes the function selectors out of its dispatcher; 'metadata' parses the trailing solc CBOR metadata. | |
| offset | No | action=disassemble only: index of the first instruction to return (not a byte offset), for paging through a large contract. |