Try it Live
Run Opcode examples in the interactive playground
Utilities
Utility functions for opcode metadata, stack analysis, gas costs, and bytecode disassembly.Metadata
Opcode.info(opcode)
Get complete opcode metadata (gas cost, stack I/O, name).
opcode: BrandedOpcode- Opcode to query
Info | undefined - Metadata or undefined if invalid opcode
Opcode.getName(opcode)
Get opcode mnemonic name.
opcode: BrandedOpcode- Opcode
string | undefined - Mnemonic name or undefined
Opcode.name(opcode)
Alias for getName().
Opcode.getDescription(opcode)
Get human-readable opcode description.
opcode: BrandedOpcode- Opcode
string | undefined - Description
Opcode.getCategory(opcode)
Get opcode category.
opcode: BrandedOpcode- Opcode
string | undefined - Category
Stack Analysis
Opcode.getStackInput(opcode)
Get number of stack items consumed.
opcode: BrandedOpcode- Opcode
number | undefined - Stack inputs
Opcode.getStackOutput(opcode)
Get number of stack items produced.
opcode: BrandedOpcode- Opcode
number | undefined - Stack outputs
Opcode.getStackEffect(opcode)
Get net stack effect (outputs - inputs).
opcode: BrandedOpcode- Opcode
number | undefined - Net stack change
Gas Costs
Opcode.getGasCost(opcode)
Get static base gas cost.
opcode: BrandedOpcode- Opcode
number | undefined - Base gas cost
Note: Many opcodes have dynamic gas costs depending on runtime state (e.g., SSTORE, CALL, CREATE). This returns only the base/minimum cost.
PUSH/DUP/SWAP Utilities
Opcode.pushBytes(opcode)
Get number of immediate bytes for PUSH opcode.
opcode: BrandedOpcode- Opcode
number | undefined - Byte count or undefined
Opcode.dupPosition(opcode)
Get stack position duplicated by DUP opcode (1-16).
opcode: BrandedOpcode- Opcode
number | undefined - Position (1-16) or undefined
Opcode.swapPosition(opcode)
Get stack position swapped by SWAP opcode (1-16).
opcode: BrandedOpcode- Opcode
number | undefined - Position (1-16) or undefined
Opcode.logTopics(opcode)
Get number of topics for LOG opcode (0-4).
opcode: BrandedOpcode- Opcode
number | undefined - Topic count (0-4) or undefined
Disassembly
Opcode.disassemble(bytecode)
Disassemble bytecode to human-readable assembly.
bytecode: Uint8Array- Raw bytecode
string[] - Array of formatted instruction strings
Format: "<offset>: <mnemonic> [immediate]"
Opcode.format(instruction)
Format single instruction as string.
instruction: Instruction- Parsed instruction
string - Formatted string
Utility Patterns
Calculate Stack Depth
Estimate Gas Cost
Group by Category
Pretty Print Assembly
Extract PUSH Values
See Also
- Constructors - Parsing and constants
- Validation - Opcode validation
- Usage Patterns - Analysis examples

