import { Address, Wei, Gwei, Ether } from '@tevm/voltaire';
import { Hex } from '@tevm/voltaire/Hex';
import { Bytes32 } from '@tevm/voltaire/Bytes32';
import { Rlp } from '@tevm/voltaire/Rlp';
import { Abi } from '@tevm/voltaire/Abi';
import { Keccak256 } from '@tevm/voltaire/Keccak256';
// Addresses - branded Uint8Array with type safety
const addr = Address('0x742d35Cc6634C0532925a3b844Bc9e7595f51e3e');
console.log(addr.toHex()); // "0x742d35cc..."
console.log(addr.toChecksummed()); // "0x742d35Cc..."
// Denominations - type-safe ETH value handling
const value = Wei(1000000000000000000n);
console.log(Wei.toEther(value)); // "1"
console.log(Wei.toGwei(value)); // "1000000000"
// Type safety prevents denomination confusion
// ❌ This won't compile - Wei and Gwei are incompatible types
// const confusion: WeiType = someGweiValue; // Type Error!
// Fixed-size bytes
const hash = Bytes32('0x' + '12'.repeat(32));
console.log(hash.toHex());
// Keccak256 hashing
const messageHash = Keccak256('hello');
const selector = Keccak256.selector('transfer(address,uint256)');
// Uint8Array(4) [0xa9, 0x05, 0x9c, 0xbb]
// RLP encoding
const encoded = Rlp.encode([addr, Hex.fromNumber(42n)]);
const decoded = Rlp.decode(encoded);
// ABI encoding
const transferAbi = {
type: 'function',
name: 'transfer',
inputs: [
{ type: 'address', name: 'to' },
{ type: 'uint256', name: 'amount' }
],
outputs: [{ type: 'bool' }],
stateMutability: 'nonpayable'
} as const;
const calldata = Abi.Function.encodeParams(transferAbi, [
'0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
1000000000000000000n
]);