Skip to main content
Scenario: You are shipping a treasury sweeper that moves USDC from hot wallets to cold storage and logs every receipt hash. Five minutes before deploy, someone refactors recordSweep and swaps two arguments.

Spot the Bug Before Scrolling

Both HexAddress and TxHash collapse to `0x${string}`. TypeScript is structurally typed, so two aliases for the same template string are completely interchangeable. Worse, gasPriceGwei (30 gwei) was passed where wei was expected — off by a factor of 10^9.
  1. type HexAddress = \0x$`creates an alias, not a distinct type. SwappingtxHash(32 bytes) andvault` (20 bytes) satisfies the same string shape.
  2. Plain bigint carries no unit. Nothing stops Gwei from flowing into a Wei parameter.
  3. On top of that, '0x742d...e3e' === '0x742d...E3e' evaluates to false if one side is EIP-55 checksummed and the other is lowercase.

Under the Hood: What an Address Actually Is

An Ethereum address is never a string on the wire or in the EVM. It is 20 raw bytes (160 bits). Strings are only for humans and JSON-RPC. Voltaire stores Address as a branded 20-byte Uint8Array. At runtime it is a plain Uint8Array with zero wrapper allocation. At compile time, a phantom unique symbol brand makes AddressType incompatible with HashType, BytecodeType, and raw Uint8Array.

Step-by-Step: Make the Bug Impossible to Compile

1

Lock down the function signature with branded types

Import the constructors from @tevm/voltaire and their types. Construct values once at the boundary (HTTP input, env var, RPC payload) — never re-validate inside business logic.
2

Kill casing bugs forever

Because Voltaire stores 20 raw bytes, lowercase, uppercase, and EIP-55 checksummed inputs produce byte-identical values.
Need to reject a user-pasted address with a typo? Check Address.isValidChecksum(input) before calling Address(input). EIP-55 encodes a 40-bit checksum in letter capitalization, catching 99.97% of single-character typos.
3

Derive an EOA address from a private key

Watch the diagram from earlier come alive in four lines:
4

Predict a counterfactual contract address with CREATE2

Smart wallets (Safe, ERC-4337) receive funds before the contract is deployed. How? CREATE2 computes the address deterministically from four inputs:

What You Built

  • Replaced untyped 0x${string} and raw bigint parameters with AddressType, HashType, and WeiType.
  • Verified why Address eliminates casing bugs by storing 20 raw bytes.
  • Derived Anvil account #0 manually from secp256k1 + Keccak-256 and matched it with Address.fromPrivateKey.
  • Computed a counterfactual CREATE2 contract address offline.
Next tutorial: Tutorial 2: Reading Raw Calldata Like an EVM