| Crates.io | openzeppelin-stylus-proc |
| lib.rs | openzeppelin-stylus-proc |
| version | 0.3.0 |
| created_at | 2024-10-15 11:18:19.371376+00 |
| updated_at | 2025-08-06 20:35:16.254121+00 |
| description | Procedural macros for OpenZeppelin Stylus contracts |
| homepage | |
| repository | https://github.com/OpenZeppelin/rust-contracts-stylus |
| max_upload_size | |
| id | 1409311 |
| size | 12,813 |
Procedural macros for OpenZeppelin Stylus Contracts, providing tools to streamline trait definitions, interface ID computation, and Solidity compatibility in Rust-based Stylus Contracts.
This crate offers procedural macros for OpenZeppelin Stylus Contracts, specifically targeting the computation of Solidity interfaceId value and enhancing trait implementations with clear and robust syntax.
#[interface_id] Macro: Adds interface_id() function that computes Solidity-compatible interface ID for traits.#[selector] Attribute: Overrides function names to align with Solidity method signatures.#[interface_id]Annotate a Rust trait with #[interface_id] to add the Solidity-compatible interface ID calculation:
use openzeppelin_stylus_proc::interface_id;
#[interface_id]
pub trait IErc721 {
type Error: Into<alloc::vec::Vec<u8>>;
fn balance_of(&self, owner: Address) -> Result<U256, Self::Error>;
fn owner_of(&self, token_id: U256) -> Result<Address, Self::Error>;
// ...
}
This will add interface_id() function that caluclates interface ID based on the XOR of the function selectors.
#[selector]Override the Solidity function selector explicitly:
fn safe_transfer_from(
&mut self,
from: Address,
to: Address,
token_id: U256,
) -> Result<(), Self::Error>;
// Solidity allows function overloading, but Rust does not, so we map
// the Rust function name to the appropriate Solidity function name.
#[selector(name = "safeTransferFrom")]
fn safe_transfer_from_with_data(
&mut self,
from: Address,
to: Address,
token_id: U256,
data: Bytes,
) -> Result<(), Self::Error>;
This ensures compatibility with Solidity's naming conventions.
Refer to our Security Policy for more details.