eth.zig
The fastest Ethereum library. Beats Rust on 18 of 26 benchmarks.
The fastest Ethereum library. Beats alloy.rs on 18 of 26 benchmarks.
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?
- Faster than Rust -- eth.zig beats alloy.rs (Rust's leading Ethereum library, backed by Paradigm) on 18 out of 26 benchmarks, including secp256k1 signing (2.34x), ABI decoding (8.41x), mulDiv (1.82x), u256 division (3.43x), and Keccak-256 hashing of small inputs.
- 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.
Performance vs alloy.rs
eth.zig wins 18/26 benchmarks against alloy.rs (alloy-primitives 1.6.0, alloy-consensus 2.0.5; run 2026-06-10). Measured on Apple Silicon, ReleaseFast (Zig) vs --release (Rust).
| Operation | eth.zig | alloy.rs | Winner |
|---|---|---|---|
| secp256k1 sign | 22,033 ns | 51,490 ns | zig 2.34x |
| secp256k1 sign+recover | 52,095 ns | 220,150 ns | zig 4.23x |
| ABI decode (dynamic) | 32 ns | 269 ns | zig 8.41x |
| ABI encode (static) | 25 ns | 97 ns | zig 3.88x |
| RLP encode (EIP-1559 tx) | 3 ns | 73 ns | zig 24.33x |
| u256 division | 7 ns | 24 ns | zig 3.43x |
| u256 mulDiv (512-bit) | 17 ns | 31 ns | zig 1.82x |
| Keccak-256 (32B) | 263 ns | 319 ns | zig 1.21x |
| TX hash (EIP-1559) | 271 ns | 361 ns | zig 1.33x |
See the full benchmark results for all 26 operations.
Quick Start
const std = @import("std");
const eth = @import("eth");
pub fn main() !void {
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
defer _ = gpa.deinit();
const allocator = gpa.allocator();
// WARNING: This is the default Anvil/Hardhat test key. Never use it for real funds.
const private_key = try eth.hex.hexToBytesFixed(32, "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80");
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", eth.runtime.blockingIo());
defer transport.deinit();
var provider = eth.provider.Provider.init(allocator, &transport);
const recipient_address = try eth.hex.hexToBytesFixed(20, "0000000000000000000000000000000000000000");
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;
}Guides
Resources
- GitHub: eth.zig repository
- Twitter: @StrobeLabs