Stellar Macros
Procedural attribute macros for Stellar contracts, providing compile-time checks for access control and pausable patterns.
This crate is part of the OpenZeppelin Stellar Contracts library, which is published as separate crates on crates.io:
- stellar-access: Role-based access controls and ownable
- stellar-accounts: Smart accounts with custom authentication and authorization
- stellar-contract-utils: Utilities for contracts (pausable, upgradeable, cryptography, etc.)
- stellar-fee-abstraction: Fee abstraction utilities
- stellar-governance: Governance utilities (governor, votes, timelock)
- stellar-macros: Proc macros (
#[only_owner],#[when_not_paused], etc.) - stellar-tokens: Token types (fungible, non-fungible, real-world assets, vaults)
Refer to the OpenZeppelin for Stellar Contracts page for additional information.
Access Control Macros
Macros for role-based and ownership-based access control.
Usage Examples
use ;
use ;
;
Available Macros
#[only_admin]: Restricts access to admin only#[only_role(account, "role")]: Role check with authorization#[has_role(account, "role")]: Role check without authorization#[has_any_role(account, ["role1", "role2"])]: Multiple role check without authorization#[only_any_role(account, ["role1", "role2"])]: Multiple role check with authorization#[only_owner]: Restricts access to owner only
Important: Some macros perform role checking without authorization, while others include both:
- Role Check Only (
#[has_role],#[has_any_role]): Verify role membership but don't callrequire_auth() - Role Check + Auth (
#[only_role],#[only_any_role]): Verify role membership AND callrequire_auth()
Use role-only macros when your function already contains require_auth() calls to avoid duplicate authorization panics.
Pausable Macros
Macros for implementing pausable functionality in contracts.
Usage Examples
use ;
use ;
;
Available Macros
#[when_not_paused]: Function executes only when contract is not paused#[when_paused]: Function executes only when contract is paused
Installation
Add this to your Cargo.toml:
[]
# We recommend pinning to a specific version, because rapid iterations are expected as the library is in an active development phase.
= "=0.7.2"
Examples
See the following examples in the repository:
examples/fungible-pausable/- Pausable macros usageexamples/nft-access-control/- Access control macros
License
This package is part of the Stellar Contracts library and follows the same licensing terms.