A collection of Soroban contract implementations and interface clients.
This is experimental software and is provided on an "as is" and "as available" basis.
We do not give any warranties and will not be liable for any loss incurred through any use of this codebase.
Add this to your Cargo.toml
:
toml
[dependencies]
soroban-contracts = "<desired version>"
Contract clients are generated from a Rust trait using the soroban-sdk. They can be imported and used as follows:
```rust use stellarsdk::{BytesN, Env}; use sorobancontracts::token::{TokenClient};
let env = Env::default(); let usdcaddress = BytesN::fromarray(&env, &[u8; 0]); let usdc = TokenClient::new(&env, BytesN::fromarray(&env, &usdcaddress));
// perform an action against the usdc contract... ```
For each function defined in the trait like balance
, the client contains a standard balance
function that obeys the interface and a try_balance
that wraps the returned value in a Result
to allow the calling contract to gracefully handle errors if required.
Traits can be implemented for a contract through a Rust impl
tag and a contractimpl attribute.
```rust use sorobansdk::{contractimpl}; use sorobancontracts::token::{Token};
pub struct MyContract;
impl Token for MyContract { // implement the Token trait based on your contract's needs } ```
Implemented contracts expose their optimized WASM bundle. This bundle can be used to deploy to networks or used in tests as shown below:
```rust use sorobansdk::{testutils::{BytesN as _}, BytesN, Env}; use sorobancontracts::token::{TokenWASM, TokenClient};
let e = Env::default(); let contractid = BytesN::<32>::random(&e); e.registercontractwasm(&contractid, TokenWASM); let tokenclient = TokenClient::new(e, &contractid);
// perform an action against the newly deployed token contract... ```
This library only supports contracts that have been agreed upon by the community via a SEP or CAP.
Current: * token - A standardized token defined by CAP-0046-06
If there are any missing contracts - please file an issue.
This library was inspired by or directly modified from many sources, primary: - OpenZeppelin
The WASM target wasm32-unknown-unknown
is supported.
Contributions are welcome. Please check out the contribution guide (TODO)!
This library is released under the MIT License.