Crate soroban_rs_macros

Crate soroban_rs_macros 

Source
Expand description

§Soroban Macros

This crate provides procedural macros for working with Soroban smart contracts.

§Features

  • soroban! macro: Automatically generates client code for interacting with Soroban contracts by:
    • Parsing contract interface from Rust code
    • Creating type-safe client structs with matching methods
    • Handling parameter transformations and RPC communication

§Example

use soroban_rs_macros::soroban;
use soroban_rs::{xdr::ScVal, ClientContractConfigs};

soroban!(r#"
    pub struct Token;

    impl Token {
        pub fn transfer(env: &Env, from: Address, to: Address, amount: u128) -> bool {
            // Contract implementation...
        }
    }
"#);

// Generated client can be used like this:
async fn use_token_client() {
    let client_configs = ClientContractConfigs::new(/* ... */);
    let mut token_client = TokenClient::new(&client_configs);
     
    // Call the contract method with ScVal parameters
    let result = token_client.transfer(from_scval, to_scval, amount_scval).await;
}

Macros§

soroban
A procedural macro for generating Soroban contract client code.