#ethereum #event-log #decode #logs #data #decoding #ethabi

no-std ethabi-decode

Decoding of ABI-encoded data and event logs

1 stable release

1.0.0 Jan 15, 2024

#747 in Magic Beans

Download history 11604/week @ 2024-01-29 17063/week @ 2024-02-05 19577/week @ 2024-02-12 25636/week @ 2024-02-19 23164/week @ 2024-02-26 17914/week @ 2024-03-04 20010/week @ 2024-03-11 21911/week @ 2024-03-18 20746/week @ 2024-03-25 29437/week @ 2024-04-01 30902/week @ 2024-04-08 23884/week @ 2024-04-15 22940/week @ 2024-04-22 15741/week @ 2024-04-29 16206/week @ 2024-05-06

79,349 downloads per month
Used in 18 crates (3 directly)

Apache-2.0

72KB
1.5K SLoC

ethabi-decode

This library is a codec for ABI-encoded data and event logs. It is a fork of ethabi with a focus on providing decode functionality in environments where libstd may not be available.

For compatibility with constrained no_std environments, the design of this library differs from the the upstream ethabi in several respects, including:

  • ABI's need to be specified as code rather than being loaded from JSON (No SERDE support).
  • Use of Vec<u8> instead of std::string::String for owned strings.
  • Anything to do with human-readable error and display output was excised.

Building

  • Build without libstd

    cargo build --no-default-features
    
  • Build with libstd

    cargo build
    

Example

Decode an event log:

use ethabi_decode::{Event, ParamKind, Token};

fn decode_event_log(topics: Vec<H256>, data: Vec<u8>) -> Vec<Token> {

    let event = Event {
      signature: "SomeEvent(address,int256)",
      inputs: vec![
        Param { kind: ParamKind::Address, indexed: true },
        Param { kind: ParamKind::Int(256), indexed: false },
      ],
      anonymous: false,
    };

    event.decode(topics, data).unwrap()
}

Dependencies

~0.3–1.2MB
~24K SLoC