Crates.io | ethereum_abi |
lib.rs | ethereum_abi |
version | 0.4.0 |
source | src |
created_at | 2020-12-19 23:10:50.806708 |
updated_at | 2022-03-11 23:07:54.260149 |
description | Ethereum Smart Contract ABI parsing library |
homepage | |
repository | https://github.com/FelipeRosa/rust-ethereum-abi |
max_upload_size | |
id | 324724 |
size | 85,386 |
ethereum_abi
is a Rust library to help writing code that interacts with Ethereum Smart Contracts.
use std::fs::File;
use std::io;
use ethereum_abi::Abi;
fn main() {
// Parse ABI JSON file
let abi = {
let file = File::open("some_abi.json").expect("failed to open ABI file");
Abi::from_reader(file).expect("failed to parse ABI")
};
// Read some ABI encoded function input
let mut encoded_input = String::new();
io::stdin()
.read_line(&mut encoded_input)
.expect("failed to read encoded input");
// Decode
let (func, decoded_input) = abi
.decode_input_from_hex(&encoded_input.trim())
.expect("failed decoding input");
println!("function called: {}\ninput: {:?}", func.name, decoded_input);
}
use std::{fs::File, str::FromStr};
use ethereum_abi::Abi;
use web3::types::H256;
fn main() {
// Parse ABI JSON file
let abi = {
let file = File::open("some_abi.json").expect("failed to open ABI file");
Abi::from_reader(file).expect("failed to parse ABI")
};
// Log data
let topics = vec![
H256::from_str("...").unwrap(),
H256::from_str("...").unwrap(),
];
let data = "0000000...".as_bytes();
// Decode
let (evt, decoded_data) = abi
.decode_log_from_slice(&topics, data)
.expect("failed decoding log");
println!("event: {}\ndata: {:?}", evt.name, decoded_data);
}
This project is licensed under the MIT License