A library for secure smart contract development written in Rust for Arbitrum Stylus.
- Security-first smart contracts, ported from the
openzeppelin-contracts
library. - First-class
no_std
support. - Solidity constructors powered by
koba
. - Unit and integration test affordances, used in our own tests.
You can import OpenZeppelin Contracts from crates.io by adding the following
line to your Cargo.toml
(We recommend pinning to a specific version):
[dependencies]
openzeppelin-stylus = "0.1.1"
Optionally, you can specify a git dependency if you want to have the latest
changes from the main
branch:
[dependencies]
openzeppelin-stylus = { git = "https://github.com/OpenZeppelin/rust-contracts-stylus" }
Note
This library is designed to be no_std
, which helps reduce wasm size. If you want your project to be no_std
as well, ensure that your dependencies are not importing the standard library.
You can achieve this by setting default-features = false
for relevant dependencies in your Cargo.toml
. For example:
[dependencies]
alloy-primitives = { version = "=0.7.6", default-features = false }
You will also need to define your own panic handler for cargo stylus check
to pass.
Here's an example of a simple panic handler you can use in your lib.rs
file:
#[cfg(target_arch = "wasm32")]
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
The library also works on an std
environment, without the need to define a panic handler or making extra changes to your project.
Once defined as a dependency, use one of our pre-defined implementations by importing them:
use openzeppelin_stylus::token::erc20::Erc20;
sol_storage! {
#[entrypoint]
struct Erc20Example {
#[borrow]
Erc20 erc20;
}
}
#[public]
#[inherit(Erc20)]
impl Erc20Example {}
For a more complex display of what this library offers, refer to our examples.
For a full example that includes deploying and querying a contract, see the basic example.
For more information on what this library will include in the future, see our roadmap.
OpenZeppelin Contracts for Stylus exists thanks to its contributors. There are many ways you can participate and help build high-quality software. Check out the contribution guide!
Past audits can be found in audits/
.
Refer to our Security Policy for more details.
OpenZeppelin Contracts for Stylus is released under the MIT License.