soroban-sdk-tools
Proc macros and utilities for soroban-sdk that replace the repetitive parts of storage, error definitions, and auth test setup.
Getting started
Or add to your contract's Cargo.toml directly:
[]
= "0.1"
[]
= { = "0.1", = ["testutils"] }
The testutils feature pulls in auth helpers and crypto deps. Keep it in dev-dependencies so it doesn't end up in your WASM.
Storage
#[contractstorage] turns a struct into typed storage handles:
use ;
use ;
;
There's a Map and Item variant for each durability: PersistentMap<K,V> / PersistentItem<V>, InstanceMap<K,V> / InstanceItem<V>, TemporaryMap<K,V> / TemporaryItem<V>.
#[contractstorage(auto_shorten = true)] compresses keys automatically, which typically saves 30-40% on storage fees. More detail in the storage docs on docs.rs.
Error handling
#[scerr] generates a #[contracterror] enum with sequential codes and doc-comment descriptions:
use scerr;
For cross-contract calls, #[transparent] propagates errors in the same WASM via ?, and #[from_contract_client] handles try_ calls via ??:
Codes are assigned sequentially and the WASM spec comes out fully flattened, so your TypeScript bindings see every variant without gaps. See error docs for the composition rules.
Contract imports
Works like the SDK's contractimport!. The difference is it generates ContractError and ContractErrorSpec trait impls too, which #[scerr] needs for composition:
Auth testing
With testutils enabled you get helpers for mock and real-signature auth:
use ;
// Skip the crypto, just test your logic
setup_mock_auth;
client.deposit;
// Or actually sign the payload with a real passkey
let kp = generate;
let signer = setup_real_auth;
client.deposit;
Supports ed25519, secp256k1, and secp256r1. Details in the auth docs.
Examples
Working contracts in examples/ you can build and test:
increment- storage with struct and one-liner patternserrors/- composable errors across contractsauth/- token, vault, and atomic swap with auth testingfeatures/- feature-gated storage
License
Apache-2.0
Acknowledgments
Inspired by loam-soroban-sdk.