#ethereum #abi #json #serde #serialization

no-std alloy-json-abi

Full Ethereum JSON-ABI implementation

17 releases (4 breaking)

new 0.6.4 Feb 29, 2024
0.6.2 Jan 25, 2024
0.5.4 Dec 28, 2023
0.5.1 Nov 30, 2023
0.3.1 Jul 30, 2023

#943 in Magic Beans

Download history 2342/week @ 2023-11-09 2295/week @ 2023-11-16 3774/week @ 2023-11-23 4431/week @ 2023-11-30 4386/week @ 2023-12-07 4262/week @ 2023-12-14 3268/week @ 2023-12-21 3534/week @ 2023-12-28 4634/week @ 2024-01-04 5652/week @ 2024-01-11 6463/week @ 2024-01-18 8347/week @ 2024-01-25 7237/week @ 2024-02-01 8241/week @ 2024-02-08 10605/week @ 2024-02-15 7647/week @ 2024-02-22

35,422 downloads per month
Used in 15 crates (10 directly)

MIT/Apache

495KB
11K SLoC

alloy-json-abi

Full Ethereum JSON-ABI implementation.

This crate is a re-implementation of a part of ethabi's API, with a few main differences:

  • the Contract struct is now called JsonAbi and also contains the fallback and receive functions
  • the Param and EventParam structs only partially parse the type string instead of fully resolving it into a Solidity type

Examples

Parse a JSON ABI file into a JsonAbi struct:

use alloy_json_abi::JsonAbi;

# stringify!(
let path = "path/to/abi.json";
let json = std::fs::read_to_string(path).unwrap();
# );
# let json = "[]";
let abi: JsonAbi = serde_json::from_str(&json).unwrap();
for item in abi.items() {
    println!("{item:?}");
}

Resolve a Function's input type with alloy-dyn-abi:

todo!()

Dependencies

~4–6.5MB
~134K SLoC