recordSweep and swaps two arguments.
Spot the Bug Before Scrolling
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.
Check your understanding: Why didn't TypeScript catch either bug?
Check your understanding: Why didn't TypeScript catch either bug?
type HexAddress = \0x$`creates an alias, not a distinct type. SwappingtxHash(32 bytes) andvault` (20 bytes) satisfies the same string shape.- Plain
bigintcarries no unit. Nothing stopsGweifrom flowing into aWeiparameter. - On top of that,
'0x742d...e3e' === '0x742d...E3e'evaluates tofalseif 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 storesAddress 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 rawbigintparameters withAddressType,HashType, andWeiType. - Verified why
Addresseliminates 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
CREATE2contract address offline.

