Utilities

The OpenZeppelin Stylus Contracts provides a ton of useful utilities that you can use in your project. For a complete list, check out the API Reference. Here are some of the more popular ones.

Introspection

It’s frequently helpful to know whether a contract supports an interface you’d like to use. ERC-165 is a standard that helps do runtime interface detection. Contracts for Stylus provides helpers for implementing ERC-165 in your contracts:

sol_storage! {
    #[entrypoint]
    struct Erc721Example {
        #[borrow]
        Erc721 erc721;
    }
}

#[public]
#[inherit(Erc721)]
impl Erc721Example {
    pub fn supports_interface(interface_id: FixedBytes<4>) -> bool {
        Erc721::supports_interface(interface_id)
    }
}

Structures

Some use cases require more powerful data structures than arrays and mappings offered natively in alloy and the Stylus sdk. Contracts for Stylus provides these libraries for enhanced data structure management:

  • BitMaps: Store packed booleans in storage.

  • Checkpoints: Checkpoint values with built-in lookups.