ContractAddress
Utility functions for computing Contract Addresses.
Examples
Below are some examples demonstrating common usages of the ContractAddress
module:
Computing Contract Addresses (CREATE)
A Contract Address that was instantiated using the CREATE
opcode can be computed using ContractAddress.fromCreate
:
import { ContractAddress } from 'ox'
ContractAddress.fromCreate({
from: '0x1a1e021a302c237453d3d45c7b82b19ceeb7e2e6',
nonce: 0n,
})
'0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2'
Computing Contract Addresses (CREATE2)
A Contract Address that was instantiated using the CREATE2
opcode can be computed using ContractAddress.fromCreate2
:
import { Bytes, ContractAddress, Hex } from 'ox'
ContractAddress.fromCreate2({
from: '0x1a1e021a302c237453d3d45c7b82b19ceeb7e2e6',
bytecode: Bytes.from('0x6394198df16000526103ff60206004601c335afa6040516060f3'),
salt: Hex.fromString('hello world'),
})
'0x59fbB593ABe27Cb193b6ee5C5DC7bbde312290aB'
Functions
Name | Description |
---|---|
ContractAddress.from | Computes Contract Address generated by the CREATE or CREATE2 opcode. |
ContractAddress.fromCreate | Computes contract address via CREATE opcode. |
ContractAddress.fromCreate2 | Computes contract address via CREATE2 opcode. |