Ethereum Methods
Specialized Keccak256 methods for Ethereum protocol operations: function selectors, event topics, and contract address derivation (CREATE/CREATE2).selector(signature)
Compute function selector (first 4 bytes of Keccak256 hash). Signature:signature(string) - Function signature (e.g.,"transfer(address,uint256)")
Uint8Array (4 bytes) - Function selector
Throws: Never throws for valid signature string
- Basic Usage
- Building Calldata
- Common Selectors
- Selector Lookup
- Returns first 4 bytes of
Keccak256.hashString(signature) - Signature format:
functionName(type1,type2,...)(no spaces, no param names) - Canonical types required:
uint256notuint,addressnotaddress payable - Case-sensitive -
Transfer≠transfer
topic(signature)
Compute event topic (32-byte Keccak256 hash). Signature:signature(string) - Event signature (e.g.,"Transfer(address,address,uint256)")
Keccak256Hash (32 bytes) - Event topic hash
Throws: Never throws for valid signature string
- Basic Usage
- Event Filtering
- Common Topics
- Topic Decoding
- Returns full 32 bytes (unlike selector which returns 4 bytes)
- Used as
topics[0]in Ethereum event logs - Indexed event parameters become additional topics (
topics[1],topics[2], etc.) - Non-indexed parameters in log
datafield
contractAddress(sender, nonce)
Compute contract address from deployer and nonce (CREATE opcode). Signature:sender(Uint8Array) - Deployer address (20 bytes)nonce(bigint) - Transaction nonce
Uint8Array (20 bytes) - Contract address
Throws:
InvalidLengthError- Sender not 20 bytes
- Basic Usage
- Predicting Deployment
- Contract Factory
- Reverse Lookup
- Formula defined in Ethereum Yellow Paper
- RLP encoding:
[sender, nonce]where sender is 20 bytes, nonce is minimal big-endian - Last 20 bytes of hash become contract address
- Nonce increments with each transaction from sender
- Deterministic - same sender + nonce always produces same address
create2Address(deployer, salt, initCodeHash)
Compute contract address using CREATE2 opcode (EIP-1014). Signature:deployer(Uint8Array) - Deployer address (20 bytes)salt(Uint8Array) - 32-byte saltinitCodeHash(Uint8Array) - 32-byte hash of initialization code
Uint8Array (20 bytes) - Contract address
Throws:
InvalidLengthError- Deployer not 20 bytesInvalidLengthError- Salt not 32 bytesInvalidLengthError- initCodeHash not 32 bytes
- Basic Usage
- Deterministic Deployment
- Minimal Proxy (EIP-1167)
- Salt Generation
- Defined in EIP-1014
- Enables deterministic deployment independent of nonce
- Same deployer + salt + initCode always produces same address
0xffprefix distinguishes from CREATE (prevents collision)- initCode hashed separately (allows large bytecode)
- Commonly used for counterfactual instantiation, proxy factories
| Feature | CREATE | CREATE2 |
|---|---|---|
| Depends on nonce | Yes | No |
| Depends on initCode | Indirectly (via nonce) | Yes (hashed) |
| Predictable | Requires knowing nonce | Always predictable |
| Redeployable | No (nonce increments) | No (same address) |
| Use case | Normal deployment | Counterfactual, upgradeable proxies |
Usage Examples
Full Contract Deployment Flow
Function Call Decoding
Event Log Processing
Related
- Core Hashing Methods - Basic hash, hashString, hashHex
- Usage Patterns - Common patterns and best practices
- Implementations - Implementation comparison
- ABI Module - ABI encoding/decoding for selectors and topics

