| Crates.io | soroban-rs-macros |
| lib.rs | soroban-rs-macros |
| version | 0.2.4 |
| created_at | 2025-04-04 11:48:39.399072+00 |
| updated_at | 2025-09-24 22:21:41.030901+00 |
| description | A collection of helpers for writing tests for Soroban contracts |
| homepage | |
| repository | https://github.com/OpenZeppelin/soroban-helpers |
| max_upload_size | |
| id | 1619852 |
| size | 12,870 |
A procedural macro library that simplifies working with Soroban smart contracts by automatically generating client code.
The soroban! macro automatically generates client code for interacting with Soroban contracts by:
Add the dependency to your Cargo.toml:
[dependencies]
soroban-rs-macros = { version = "0.2.4" }
soroban-rs = { version = "0.2.6" }
use soroban_rs_macros::soroban;
use soroban_rs::{xdr::ScVal, ClientContractConfigs, GetTransactionResponse, SorobanHelperError};
// Define your contract interface
soroban!(r#"
pub struct Token;
impl Token {
pub fn transfer(env: &Env, from: Address, to: Address, amount: u128) -> bool {
// Contract implementation...
}
}
"#);
// Use the generated client
async fn use_token_client() -> Result {
// Set up client configuration
let client_configs = ClientContractConfigs {
// ... configuration details
};
// Create client instance
let mut token_client = TokenClient::new(&client_configs);
// Call contract method with ScVal parameters
let from_scval = /* ... */;
let to_scval = /* ... */;
let amount_scval = /* ... */;
token_client.transfer(from_scval, to_scval, amount_scval).await
}
For a contract named Token, the macro generates:
TokenClient struct with client configurationnew method to instantiate the client passing the deployed contract configs:
We welcome contributions from the community! Here's how you can get involved:
If you are looking for a good place to start, find a good first issue here.
You can open an issue for a bug report, feature request, or documentation request.
You can find more details in our Contributing guide.
Please read our Code of Conduct and check the Security Policy for reporting vulnerabilities.
This project is licensed under MIT - see the LICENSE file for details.
If you discover a security vulnerability within this project, please see SECURITY.md for instructions on responsible disclosure.
See CODEOWNERS file for the list of project maintainers.