Skip to main content

Try it Live

Run Address examples in the interactive playground
This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.
View the complete executable example at playground/src/examples/primitives/address/create.ts.
import { Address } from '@tevm/voltaire'

// Auto-injected keccak256 and RLP encoder
const deployer = Address("0x742d35Cc6634C0532925a3b844Bc9e7595f51e3e")
const contract = Address.calculateCreateAddress(deployer, 0n)
console.log(contract.toHex())

Algorithm

  1. RLP encode sender address and nonce as list: [address, nonce]
  2. Hash with keccak256 producing 32-byte hash
  3. Extract address from last 20 bytes: hash[12:32]
Pseudocode:
rlp_data = rlp([sender_address, nonce])
hash = keccak256(rlp_data)
contract_address = hash[12:32]

Nonce Handling

Nonce encoding: RLP encodes nonce as minimal big-endian bytes (no leading zeros) Examples:
  • Nonce 0 → empty bytes []
  • Nonce 1[0x01]
  • Nonce 127[0x7f]
  • Nonce 255[0xff]
  • Nonce 256[0x01, 0x00]

Complete Example

import { Address } from '@tevm/voltaire'

// Deployer address
const deployer = Address("0x742d35Cc6634C0532925a3b844Bc9e7595f51e3e")

// Track deployed contracts
const deployedContracts: Address[] = []

// Deploy first contract (nonce 0)
const contract1 = deployer.calculateCreateAddress(0n)
deployedContracts.push(contract1)
console.log(`Contract 1: ${contract1.toHex()}`)

// Deploy second contract (nonce 1)
const contract2 = deployer.calculateCreateAddress(1n)
deployedContracts.push(contract2)
console.log(`Contract 2: ${contract2.toHex()}`)

// Each deployment increments nonce
for (let i = 2; i < 10; i++) {
  const contract = deployer.calculateCreateAddress(BigInt(i))
  deployedContracts.push(contract)
}

Use Cases

Predicting Contract Addresses

Calculate address before deployment:
import { Address } from '@tevm/voltaire'

async function deployContract(deployer: Address, bytecode: Uint8Array) {
  // Get current nonce
  const nonce = await provider.getTransactionCount(deployer.toHex())

  // Predict contract address
  const predictedAddress = deployer.calculateCreateAddress(BigInt(nonce))

  // Deploy contract
  const tx = await signer.sendTransaction({
    data: bytecode
  })

  await tx.wait()

  // Verify prediction
  console.log(`Predicted: ${predictedAddress.toHex()}`)
  console.log(`Actual: ${tx.contractAddress}`)
  // Should match!
}

Factory Contracts

Track contract addresses deployed by factory:
import { Address } from '@tevm/voltaire'

class ContractFactory {
  constructor(private factoryAddress: Address) {}

  async getDeployedAddress(deploymentIndex: bigint): Promise<Address> {
    // Factory's nonce when deploying this contract
    const nonce = await this.getFactoryNonceAtDeployment(deploymentIndex)

    return this.factoryAddress.calculateCreateAddress(nonce)
  }
}

Address Validation

Verify contract was deployed by expected address:
import { Address } from '@tevm/voltaire'

function verifyContractOrigin(
  contract: Address,
  expectedDeployer: Address,
  nonce: bigint
): boolean {
  const calculated = expectedDeployer.calculateCreateAddress(nonce)
  return calculated.equals(contract)
}

CREATE vs CREATE2

FeatureCREATECREATE2
DeterminismNonce-based (sequential)Salt-based (arbitrary)
DependenciesKeccak256, RLPKeccak256 only
Parameters(address, nonce)(address, salt, initCode)
PredictabilityRequires tracking nonceFully deterministic always
RedeploymentDifferent address each timeSame address if inputs identical

Performance

Cryptographic operations:
  • RLP encoding (~O(n) where n = nonce size)
  • keccak256 hash
Bundle size impact: Adds keccak256 + RLP encoder (~10-15 KB total) Dependencies:
  • keccak256 - Hash function for address derivation
  • rlpEncode - RLP encoding for [address, nonce] list
Use Factory API for tree-shakeable builds that inject these dependencies explicitly.

Error Handling

import { Address } from '@tevm/voltaire'

const deployer = Address("0x742d35Cc6634C0532925a3b844Bc9e7595f51e3e")

// Valid nonces
console.log(deployer.calculateCreateAddress(0n))   // ✓
console.log(deployer.calculateCreateAddress(100n)) // ✓

// Invalid: negative nonce
try {
  deployer.calculateCreateAddress(-1n)
} catch (e) {
  console.error(e) // InvalidValueError: Nonce cannot be negative
}

See Also