#stark-net #web3 #cainome #back-end

cainome-rs

A run-time library to generate rust bindings for cairo contracts

3 releases (breaking)

new 0.3.0 May 8, 2025
0.2.0 Apr 16, 2025
0.1.0 Feb 7, 2025

#426 in Magic Beans

Download history 111/week @ 2025-02-02 22/week @ 2025-02-09 21/week @ 2025-02-16 11/week @ 2025-02-23 151/week @ 2025-03-02 237/week @ 2025-03-09 347/week @ 2025-03-16 392/week @ 2025-03-23 286/week @ 2025-03-30 320/week @ 2025-04-06 833/week @ 2025-04-13 779/week @ 2025-04-20 802/week @ 2025-04-27 701/week @ 2025-05-04

3,119 downloads per month
Used in 4 crates (2 directly)

MIT/Apache

255KB
6K SLoC

Cainome Rust backend

This crates contains the run-time library to generate rust bindings (using Cairo Serde).

This crate is used as built-in plugin of cainome CLI, and is mainly published to expose the library used by abigen! macro in cainome-rs-macro crate.

For more details on what's generated, check the rs-macro README.

This crate however exposes a Abigen struct that can be used to programmatically generate bindings for a contract.

Example

use cainome::rs::Abigen;
use std::collections::HashMap;

#[tokio::main]
async fn main() {
    let mut aliases = HashMap::new();
    aliases.insert(String::from("my::type::Event"), String::from("MyTypeEvent"));

    let abigen = Abigen::new(
        "MyContract",
        "./contracts/target/dev/contracts_simple_get_set.contract_class.json",
    )
    .with_types_aliases(aliases)
    .with_derives(vec!["Debug".to_string(), "PartialEq".to_string()])
    .with_contract_derives(vec!["Debug".to_string(), "Clone".to_string()]);

    abigen
        .generate()
        .expect("Fail to generate bindings")
        .write_to_file("/tmp/abigen.rs")
        .unwrap();
}

Dependencies

~17–30MB
~465K SLoC