Type Definition
Creating Error Signatures
From Signature String
From Hex String
From Bytes
Operations
Convert to Hex
Compare Signatures
Standard Error Signatures
Built-in Errors
Solidity has two built-in error signatures:Panic Codes
When usingassert() or encountering specific errors, Solidity reverts with Panic(uint256) and a code:
0x00- Generic panic0x01- Assert failed0x11- Arithmetic overflow/underflow0x12- Division by zero0x21- Invalid enum value0x22- Invalid storage byte array access0x31- Pop on empty array0x32- Array out of bounds0x41- Out of memory0x51- Invalid internal function call
Custom Errors
Custom errors are more gas-efficient thanrequire() with strings:
Common Custom Errors
Access Control
Token Operations
DeFi
Revert Data Structure
When a custom error is thrown, the revert data contains:InsufficientBalance(1000, 2000):
Decoding Errors
Use error signatures to decode revert data:Signature Format
Error signatures must use canonical type names: ✅ Correct:InsufficientBalance(uint256,uint256)Unauthorized()InvalidSwap(address,uint256,bytes)
InsufficientBalance(uint, uint)(should be uint256)InsufficientBalance(uint256, uint256)(has spaces)insufficientBalance(uint256,uint256)(wrong capitalization)
How Error Signatures Work
- Error Signature: Start with the canonical error signature
- Hash: Compute
keccak256(signature) - Truncate: Take the first 4 bytes
Gas Efficiency
Custom errors are significantly more gas-efficient thanrequire() with strings:
Handling Errors
API Reference
Constructors
from(value: ErrorSignatureLike): ErrorSignatureType- Create from various inputsfromHex(hex: string): ErrorSignatureType- Create from hex stringfromSignature(signature: string): ErrorSignatureType- Compute from error signature
Operations
toHex(sig: ErrorSignatureType): string- Convert to hex stringequals(a: ErrorSignatureType, b: ErrorSignatureType): boolean- Compare signatures
See Also
- Selector - 4-byte function selector
- FunctionSignature - Extended function selector
- EventSignature - 32-byte event topic
- ABI - ABI encoding and decoding

