A collection of Rust libraries designed to simplify development and testing with Soroban, the smart contract platform for the Stellar network.
This project provides three main components:
- soroban-rs: A high-level client library for interacting with the Soroban RPC API
- soroban-rs-macros: A procedural macro that introduces
soroban!
macro for generating smart contract clients from Soroban contract definitions. - soroban-test-helpers: A procedural macro library that simplifies writing tests for Soroban smart contracts
- example: An example contract demonstrating how to use the test helpers.
A high-level client library that abstracts away the complexity of interacting with the Soroban RPC API. It provides:
- Env: Manages connections to Soroban RPC endpoints and handles network configuration
- Signer: Manages transaction signing with Stellar keypairs
- Account: Manages higher level account interactions.
- Contract: Simplifies contract deployment and interaction, including support for constructor arguments
- Transaction Builder: Helps create and manage Soroban transactions
For detailed examples of how to use soroban-rs
, please refer to the examples directory. The examples include:
deploy_and_invoke.rs
: Demonstrates deploying and invoking a contract.invoke_contract.rs
: Demonstrates invoking an already deployed contract.create_multisig.rs
: Demonstrates adding signers to an existing account.
A procedural macro that introduces soroban!
macro for generating smart contract clients from Soroban contract definitions.
use soroban_rs_macros::soroban;
soroban!(r#"
pub struct Token;
impl Token {
pub fn transfer(env: &Env, from: Address, to: Address, amount: u128) -> bool {
// Contract implementation...
}
}
"#);
async fn main() {
let token = TokenClient::new();
let res =token.transfer(from, to, amount).await;
}
A procedural macro library that simplifies writing tests for Soroban smart contracts by automatically initializing the test environment and test accounts.
The #[test]
macro transforms test functions to automatically:
- Create a default Soroban environment
- Generate test addresses
- Inject these as arguments to your test function
Instead of manually creating the test environment like this:
#[test]
fn test() {
let env = Env::default();
let alice = Address::generate(&env);
let bob = Address::generate(&env);
// Test contract functionality
// ...
}
You can use the simplified approach with soroban-test-helpers:
#[soroban_test_helpers::test]
fn test_injected_args(e: Env, alice: Address, bob: Address) {
// Test contract functionality directly with injected arguments
// ...
}
An example crate demonstrating how to use the soroban-test-helpers
, soroban-rs-macros
and soroban-rs
libraries for testing Soroban contracts. This serves as a reference implementation to show how to:
- Write testsusing both traditional methods and the simplified
soroban-test-helpers
approach. - Add scripts to your soroban project for deploying and invoking contracts.
- Use the
soroban!
macro to generate client code for interacting with Soroban contracts.
We welcome contributions from the community! Here's how you can get involved:
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
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 the MIT License - 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.