Skip to content

ZAbi logo

A zig library to interact with EVM blockchains

Overview

Zabi aims to add support for interacting with ethereum or any compatible EVM based chain.

Example Usage

const args_parser = zabi.args;
const std = @import("std");
const zabi = @import("zabi");
const Wallet = zabi.clients.wallet.Wallet(.http);
 
const CliOptions = struct {
    priv_key: [32]u8,
    url: []const u8,
};
 
pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
 
    var iter = try std.process.argsWithAllocator(gpa.allocator());
    defer iter.deinit();
 
    const parsed = args_parser.parseArgs(CliOptions, &iter);
 
    const uri = try std.Uri.parse(parsed.url);
 
    var wallet: Wallet = undefined;
    try wallet.init(parsed.priv_key, .{ .allocator = gpa.allocator(), .uri = uri });
    defer wallet.deinit();
 
    const message = try wallet.signEthereumMessage("Hello World");
    const hexed = try message.toHex(wallet.allocator);
    defer wallet.allocator.free(hexed);
    std.debug.print("Ethereum message: {s}\n", .{hexed});
}

Features

  • Json RPC with support for http/s, ws/s and ipc connections
  • Wallet instances and contract instances to use for interacting with nodes/json rpc.
  • Custom Secp256k1 ECDSA signer using only Zig and implementation of RFC6979 nonce generator.
  • Custom JSON Parser that can be used to deserialize and serialized RPC data at runtime.
  • ABI to zig types.
  • Support for EIP712.
  • Parsing of human readable ABIs into zig types with custom Parser and Lexer.
  • HD Wallet and Mnemonic passphrases.
  • RLP Encoding/Decoding.
  • SSZ Encoding/Decoding.
  • ABI Encoding/Decoding with support for Log topics encoding and decoding.
  • Parsing of encoded transactions and serialization of transaction objects.
  • Support for all transaction types and the new EIP4844 KZG commitments.
  • Support for OPStack and ENS.
  • Custom meta programming functions to transalate ABI's into zig types.
  • Support for interacting with test chains such as Anvil or Hardhat.
  • Custom RPC server used to fuzz data.
  • Custom cli args parser that translates commands to zig types and can be used to pass data to methods.
  • Custom data generator usefull for fuzzing.

And a lot more to come yet to come...

Goal

The goal of zabi is to be one of the best library to use by the ethereum ecosystem and to expose to more people to the zig programming language.

Sponsors

Individuals
awkweb
merkleplant