Try it Live
Run Opcode examples in the interactive playground
Constructors
Methods for working with EVM opcodes and parsing bytecode.Opcode Identity
Opcode(value)
Identity function for type branding. Casts number to BrandedOpcode.
value: number- Opcode byte value (0x00-0xFF)
BrandedOpcode - Branded opcode
Note: This is a zero-cost type branding function. No validation is performed. Use isValid() to check if byte is a valid opcode.
Defined in: primitives/Opcode/Opcode.js:85
Opcode Constants
All EVM opcodes exported as pre-branded constants:Bytecode Parsing
Opcode.parse(bytecode)
Parse bytecode into array of instructions with offsets and immediates.
bytecode: Uint8Array- Raw contract bytecode
Instruction[] - Array of parsed instructions
Instruction type:
- Automatically skips PUSH immediate bytes
- Handles incomplete PUSH data at end of bytecode
- Returns instruction with offset, opcode, and optional immediate data
Opcode.pushOpcode(byteCount)
Get PUSH opcode for given byte count.
byteCount: number- Number of bytes to push (1-32)
BrandedOpcode - Corresponding PUSH opcode
Throws:
- Error if byteCount < 1 or > 32
Jump Destination Analysis
Opcode.jumpDests(bytecode)
Find all valid JUMPDEST positions in bytecode.
bytecode: Uint8Array- Contract bytecode
Set<number> - Set of valid JUMPDEST offsets
Behavior:
- Correctly skips PUSH immediate data
- Only includes JUMPDEST opcodes (0x5B) not inside PUSH data
- Returns empty set if no valid JUMPDESTs found
Common Patterns
Build PUSH Instruction
Find All PUSH Instructions
Validate Jump Targets
Extract Constants
See Also
- Validation - Opcode validation and type checking
- Utilities - Metadata and categorization
- Usage Patterns - Bytecode analysis examples

