| Crates.io | stellar-access |
| lib.rs | stellar-access |
| version | 0.4.1 |
| created_at | 2025-07-22 11:43:16.804595+00 |
| updated_at | 2025-07-22 14:02:43.956541+00 |
| description | Access Control, Ownable, and Role Transfer utilities for Stellar contracts. |
| homepage | |
| repository | https://github.com/OpenZeppelin/stellar-contracts |
| max_upload_size | |
| id | 1763450 |
| size | 319,880 |
Access Control, Ownable, and Role Transfer utilities for Stellar contracts.
This package provides three main modules for managing access control in Soroban smart contracts:
The access_control module provides comprehensive role-based access control functionality:
use soroban_sdk::{contract, contractimpl, symbol_short, Address, Env};
use stellar_access::access_control::{self as access_control, AccessControl};
use stellar_macros::default_impl;
#[contract]
pub struct MyContract;
#[contractimpl]
impl MyContract {
pub fn __constructor(e: &Env, admin: Address) {
access_control::set_admin(e, &admin);
}
pub fn admin_restricted_function(e: &Env) {
access_control::enforce_admin_auth(e);
// ...
}
pub fn mint(e: &Env, to: Address, token_id: u32, caller: Address) {
access_control::ensure_role(e, &caller, &symbol_short!("minter"));
caller.require_auth();
// minting
}
}
#[default_impl]
#[contractimpl]
impl AccessControl for MyContract {}
With Macros (requires stellar-macros dependency):
use stellar_macros::{only_admin, only_role};
#[only_admin]
pub fn admin_restricted_function(e: &Env) {
// ...
}
#[only_role(caller, "minter")]
fn mint(e: &Env, to: Address, token_id: u32, caller: Address) {
// ...
}
The ownable module implements a simple ownership pattern:
use soroban_sdk::{contract, contractimpl, Address, Env};
use stellar_access::ownable::{self as ownable, Ownable};
use stellar_macros::default_impl;
#[contract]
pub struct MyContract;
#[contractimpl]
impl MyContract {
pub fn __constructor(e: &Env, owner: Address) {
ownable::set_owner(e, &owner);
}
pub fn owner_restricted_function(e: &Env) {
ownable::enforce_owner_auth(e);
// ...
}
}
#[default_impl]
#[contractimpl]
impl Ownable for MyContract {}
With Macros (requires stellar-macros dependency):
use stellar_macros::only_owner;
#[only_owner]
pub fn owner_restricted_function(e: &Env) {
// ...
}
The role_transfer module is a utility module that provides the underlying infrastructure for secure two-step role and ownership transfers used by both Access Control and Ownable modules.
Both Access Control and Ownable modules implement a two-step transfer process for critical role changes:
This mechanism prevents accidental transfers to wrong addresses or loss of control due to typos or errors.
Note: Unlike OpenZeppelin's Solidity library where role transfers can be immediate, all role transfers in this Stellar library are always two-step processes for enhanced security. This applies to both ownership transfers and admin role transfers.
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-access = "=0.4.0"
# Add this if you want to use macros
stellar-macros = "=0.4.0"
See the following examples in the repository:
examples/ownable/ - Simple ownership patternexamples/nft-access-control/ - Role-based access controlThis package is part of the Stellar Contracts library and follows the same licensing terms.