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 buildand 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
| Layer | Modules | Description |
|---|---|---|
| Primitives | primitives, uint256, hex | Address, Hash, Bytes32, u256, hex encoding |
| Encoding | rlp, abi_encode, abi_decode, abi_comptime | RLP and ABI encoding/decoding, comptime selectors |
| Crypto | secp256k1, signer, keccak, eip155 | ECDSA signing (RFC 6979), Keccak-256, EIP-155 |
| Types | transaction, receipt, block, blob | Legacy, EIP-2930, EIP-1559, EIP-4844 transactions |
| Accounts | mnemonic, hd_wallet | BIP-32/39/44 HD wallets and mnemonic generation |
| Transport | http_transport, ws_transport, provider | HTTP and WebSocket JSON-RPC transports |
| ENS | ens_namehash, ens_resolver, ens_reverse | ENS name resolution and reverse lookup |
| Client | wallet, contract, multicall, erc20, erc721 | Signing wallet, contract interaction, token wrappers |
| Standards | eip712, abi_json | EIP-712 typed data signing, JSON ABI parsing |
| Chains | chains | Ethereum, Arbitrum, Optimism, Base, Polygon |
Guides
Resources
- GitHub: eth.zig repository
- PerpCity Zig SDK: Built on top of eth.zig -- see the Zig SDK