Skip to content

Instantly share code, notes, and snippets.

@Lucas-Kohorst
Last active January 29, 2022 15:01
Show Gist options
  • Save Lucas-Kohorst/fcbcc1515e0b5978d11b7fb5bed317d6 to your computer and use it in GitHub Desktop.
Save Lucas-Kohorst/fcbcc1515e0b5978d11b7fb5bed317d6 to your computer and use it in GitHub Desktop.
Function Signatures from ABI
[package]
name = "method_decode"
version = "0.1.0"
edition = "2021"
[dependencies]
dotenv = "0.15.0"
ethabi = "15.0.0"
hex = "0.4.3"
rustc-hex = "2.1.0"
primitive-types = "0.6.1"
serde_json = "1.0.64"
[dependencies.serde]
features = ["derive"]
version = "1.0.124"
[dependencies.url]
default-features = false
version = "2.2.2"
use std::{fs, str::FromStr, sync::Arc};
use ethabi::Error;
fn main() {
let router = ethabi::Contract::load(fs::read("src/abi/abi.abi").unwrap().as_slice()).unwrap();
let iter = router.functions().into_iter();
for f in iter {
let method_id = hex::encode(f.short_signature());
println!("Function Method ID: {:?} \n\t{:?}", method_id, f);
};
}

Running

cargo new abi_decode

# edit Cargo.toml and src/main.rs with the files aboe
# create src/abi/<abi>.abi with the abi to decode

cargo run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment