getContractAddress β
Retrieves the contract address generated by the CREATE
or CREATE2
opcode β invoked after deploying a contract to the network.
Import β
ts
import { getContractAddress } from 'viem'
Usage β
ts
import { getContractAddress } from 'viem'
getContractAddress({
from: '0xc961145a54C96E3aE9bAA048c4F4D6b04C13916b',
nonce: 69420n
})
// '0xDf2e056f7062790dF95A472f691670717Ae7b1B6'
Returns β
The contract address.
Parameters β
from (optional) β
- Type:
Address
The address the contract was deployed from.
ts
getContractAddress({
from: '0xc961145a54C96E3aE9bAA048c4F4D6b04C13916b',
nonce: 69420n
})
nonce (optional) β
- Type:
Address
The nonce of the transaction which deployed the contract.
ts
getContractAddress({
from: '0xc961145a54C96E3aE9bAA048c4F4D6b04C13916b',
nonce: 69420n
})
opcode (optional) β
- Type:
"CREATE" | "CREATE2"
- Default:
"CREATE"
The opcode to invoke the contract deployment. Defaults to "CREATE"
.
ts
getContractAddress({
bytecode: '0x608060405260405161083e38038061083e833981016040819052610...',
from: '0xc961145a54C96E3aE9bAA048c4F4D6b04C13916b',
opcode: 'CREATE2',
salt: toBytes('wagmi'),
})
bytecode (optional) β
- Type:
ByteArray
|Hex
- Only applicable for
opcode: 'CREATE2'
deployments
The to-be-deployed contractβs bytecode
ts
getContractAddress({
bytecode: '0x608060405260405161083e38038061083e833981016040819052610...',
from: '0xc961145a54C96E3aE9bAA048c4F4D6b04C13916b',
opcode: 'CREATE2',
salt: toBytes('wagmi'),
})
salt (optional) β
- Type:
ByteArray
|Hex
- Only applicable for
opcode: 'CREATE2'
deployments
An arbitrary value provided by the sender.
ts
getContractAddress({
bytecode: '0x608060405260405161083e38038061083e833981016040819052610...',
from: '0xc961145a54C96E3aE9bAA048c4F4D6b04C13916b',
opcode: 'CREATE2',
salt: toBytes('wagmi'),
})