soroban

Macro soroban 

Source
soroban!() { /* proc-macro */ }
Expand description

A procedural macro for generating Soroban contract client code.

This macro parses a Soroban contract interface and generates a client struct with corresponding methods that can be used to interact with the deployed contract.

§How It Works

  1. Parses the provided Rust code containing a contract struct and implementation
  2. Extracts the contract’s public methods
  3. Generates a client struct with matching methods that:
    • Skip the first parameter (env)
    • Convert all other parameters to use ScVal types
    • Return Result<GetTransactionResponse, SorobanHelperError>

§Parameters

  • input: A string literal containing the Rust code of the contract interface

§Generated Code

For a contract named Token, the macro generates:

  • A TokenClient struct with client configuration
  • Methods matching the contract’s public interface but with modified signatures
  • A new method to instantiate the client

§Example

soroban!(r#"
    pub struct Counter;

    impl Counter {
        pub fn increment(env: &Env, amount: u32) -> u32 {
            // Contract implementation...
        }
    }
"#);
// or
soroban!("path/to/counter.rs");

// Use the generated client:
let mut counter_client = CounterClient::new(&client_configs);
let result = counter_client.increment(amount_scval).await?;