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
- Parses the provided Rust code containing a contract struct and implementation
- Extracts the contract’s public methods
- Generates a client struct with matching methods that:
- Skip the first parameter (env)
- Convert all other parameters to use
ScValtypes - 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
TokenClientstruct with client configuration - Methods matching the contract’s public interface but with modified signatures
- A
newmethod 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?;