Docs

eth.zig

The Ethereum library for Zig -- zero dependencies, comptime-first, pure Zig crypto.

The Ethereum library for Zig. eth.zig provides everything you need to interact with Ethereum from Zig -- signing transactions, encoding ABI calls, managing HD wallets, reading ERC-20 tokens, talking to nodes over JSON-RPC, and more.

Why eth.zig?

  • Zero dependencies -- Built entirely on Zig's standard library. No C bindings, no vendored C code, no system libraries. Just zig build and go.
  • Comptime-first -- Function selectors and event topics are computed at compile time with zero runtime cost. The compiler does the hashing so your program doesn't have to.
  • Pure Zig crypto -- secp256k1 ECDSA, Keccak-256, BIP-32/39/44 HD wallets -- all implemented in pure Zig. No OpenSSL, no libsecp256k1, no FFI.

Quick Start

const std = @import("std");
const eth = @import("eth");

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();

    // Derive an address from a private key
    const private_key = try eth.hex.hexToBytesFixed(32, "your_64_char_hex_private_key_here_000000000000000000000000000000");
    const signer = eth.signer.Signer.init(private_key);
    const addr = try signer.address();
    const checksum = eth.primitives.addressToChecksum(&addr);
    _ = checksum;

    // Sign and send a transaction
    var transport = eth.http_transport.HttpTransport.init(allocator, "https://rpc.example.com");
    defer transport.deinit();
    var provider = eth.provider.Provider.init(allocator, &transport);

    const recipient_address = try eth.hex.hexToBytesFixed(20, "0000000000000000000000000000000000000000"); // replace with real address
    var wallet = eth.wallet.Wallet.init(allocator, private_key, &provider);
    const tx_hash = try wallet.sendTransaction(.{
        .to = recipient_address,
        .value = eth.units.parseEther(1.0),
    });
    _ = tx_hash;
}

Modules

LayerModulesDescription
Primitivesprimitives, uint256, hexAddress, Hash, Bytes32, u256, hex encoding
Encodingrlp, abi_encode, abi_decode, abi_comptimeRLP and ABI encoding/decoding, comptime selectors
Cryptosecp256k1, signer, keccak, eip155ECDSA signing (RFC 6979), Keccak-256, EIP-155
Typestransaction, receipt, block, blobLegacy, EIP-2930, EIP-1559, EIP-4844 transactions
Accountsmnemonic, hd_walletBIP-32/39/44 HD wallets and mnemonic generation
Transporthttp_transport, ws_transport, providerHTTP and WebSocket JSON-RPC transports
ENSens_namehash, ens_resolver, ens_reverseENS name resolution and reverse lookup
Clientwallet, contract, multicall, erc20, erc721Signing wallet, contract interaction, token wrappers
Standardseip712, abi_jsonEIP-712 typed data signing, JSON ABI parsing
ChainschainsEthereum, Arbitrum, Optimism, Base, Polygon

Guides

Resources