| Crates.io | stellar-contract-utils |
| lib.rs | stellar-contract-utils |
| version | 0.4.1 |
| created_at | 2025-07-22 11:45:03.452896+00 |
| updated_at | 2025-07-22 14:03:46.345194+00 |
| description | Utilities for Stellar contracts. |
| homepage | |
| repository | https://github.com/OpenZeppelin/stellar-contracts |
| max_upload_size | |
| id | 1763453 |
| size | 181,626 |
Utilities for Stellar contracts.
The pausable module provides functionality to pause and unpause contract operations for emergency situations or maintenance.
use soroban_sdk::{contract, contractimpl, Address, Env};
use stellar_contract_utils::pausable::{self as pausable, Pausable};
use stellar_access::ownable::{self as ownable, Ownable};
use stellar_macros::{default_impl, only_owner, when_not_paused, when_paused};
#[contract]
pub struct MyContract;
#[contractimpl]
impl MyContract {
pub fn __constructor(e: &Env, owner: Address) {
ownable::set_owner(e, &owner);
}
#[when_not_paused]
pub fn normal_operation(e: &Env) {
// This function can only be called when contract is not paused
}
#[when_paused]
pub fn emergency_reset(e: &Env) {
// This function can only be called when contract is paused
}
}
#[default_impl]
#[contractimpl]
impl Pausable for MyContract {
#[only_owner]
pub fn pause(e: &Env) {
pausable::pause(e);
}
#[only_owner]
pub fn unpause(e: &Env) {
pausable::unpause(e);
}
}
#[default_impl]
#[contractimpl]
impl Ownable for MyContract {}
The upgradeable module provides a framework for safe contract upgrades and migrations with version control.
Simple Upgrade (Upgradeable):
use soroban_sdk::{
contract, contractimpl, Address, Env,
};
use stellar_access::ownable::{self as ownable, Ownable};
use stellar_contract_utils::upgradeable::UpgradeableInternal;
use stellar_macros::{default_impl, only_owner, Upgradeable};
#[derive(Upgradeable)]
#[contract]
pub struct ExampleContract;
#[contractimpl]
impl ExampleContract {
pub fn __constructor(e: &Env, owner: Address) {
ownable::set_owner(e, &owner);
}
}
impl UpgradeableInternal for ExampleContract {
fn _require_auth(e: &Env, _operator: &Address) {
ownable::enforce_owner_auth(e);
}
}
#[default_impl]
#[contractimpl]
impl Ownable for ExampleContract {}
The crypto module provides cryptographic utilities including hash functions and Merkle tree verification.
use soroban_sdk::{Bytes, BytesN, Env};
use stellar_contract_utils::crypto::{hasher::Hasher, keccak::Keccak256};
pub fn hash_data(e: &Env, data: Bytes) -> BytesN<32> {
let mut hasher = Keccak256::new(e);
hasher.update(data);
hasher.finalize()
}
The merkle_distributor module implements a Merkle-based claim distribution system for snapshot-based voting and token distributions.
Add this to your Cargo.toml:
[dependencies]
# We recommend pinning to a specific version, because rapid iterations are expected as the library is in an active development phase.
stellar-contract-utils = "=0.4.0"
# Add this if you want to use macros
stellar-macros = "=0.4.0"
See the following examples in the repository:
examples/pausable/ - Pausable contract functionalityexamples/upgradeable/ - Contract upgrade patternsexamples/fungible-merkle-airdrop/ - Merkle-based token distributionThis package is part of the Stellar Contracts library and follows the same licensing terms.