5 releases
0.1.6 | Feb 25, 2023 |
---|---|
0.1.5 | Feb 24, 2023 |
0.1.4 | Feb 15, 2023 |
0.1.3 | Feb 14, 2023 |
0.1.2 | Feb 14, 2023 |
#232 in #ethereum
423 downloads per month
Used in 2 crates
5KB
ethbind-rs
ethbind-rs is an ethereum contract binding code generation framework for arbitrary programming languages.
Generator
The binding processor generates arbitrary programming languages codes by calling the corresponding generator
,The code generator is a rust structure that implements Generator
trait.
So far, the only official generator is the rust
bind code Generator
, you can easily use this generator in your Rust code in two ways:
via proc-macro
Using the builtin proc-macro
contract!($binder_json_path,$abi_json_path) to directly derive contract bind interface in your rust code, e.g:
contract!(include_str!("xxx/binder.json"),include_str!("xxx/Lock.json"));
The above line of rust code will generating Lock
contract bind codes in place via loading contract abi from Lock.json
file.
via build.rs
Of course, you can directly call binding processor in build.rs:
First, Add ethbind-rs in Cargo.toml
[build-dependencies]
ethbind-rs = "^0.1"
Second, Add blow lines of code in build.rs
/// + use rust `gen_codes` fn
use ethbind::gen::{ JsonRuntimeBinder,SaveTo };
use ethbind::rust::*;
fn main() {
println!("cargo:rerun-if-changed=sol");
// + load runtime type binding information
let runtime_binder: JsonRuntimeBinder = include_str!("xxx/binder.json").parse().expect("Load binder information");
// + define output directory
let output_dir = "src/sol";
let mut contracts = BindingBuilder::new((RustGenerator::default(), runtime_binder))
.bind_hardhat(include_str!("xxx/Lock.json"))
.bind_hardhat(include_str!("xxx/Swap.json"))
.finalize()
.expect("Generate data");
contracts.pretty().expect("Pretty");
contracts.save_to(output_dir).expect("Save generated");
// other codes..
}
Dependencies
~4–6MB
~102K SLoC