A library for secure smart contract development written in Cairo for Starknet, a decentralized ZK Rollup.
Warning This repo contains highly experimental code. It has no code coverage checks. It hasn't been audited. Use at your own risk.
Warning Expect rapid iteration. Some contracts or features are not ready to be deployed. Check the Unsupported section below.
Simply install Cairo and scarb.
Create a new project and cd into it.
scarb new my_project && cd my_projectThe contents of my_project should look like this:
$ ls
Scarb.toml srcEdit scarb.toml and add:
[dependencies]
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.10.0" }Build the project to download it:
$ scarb build
Updating git repository https://github.com/OpenZeppelin/cairo-contracts
Compiling my_project v0.1.0 (~/my_project/Scarb.toml)
Finished release target(s) in 6 secondsOpen src/lib.cairo and write your contract.
For example, this is how to write an ERC20-compliant contract:
#[starknet::contract]
mod MyToken {
use openzeppelin::token::erc20::ERC20Component;
use starknet::ContractAddress;
component!(path: ERC20Component, storage: erc20, event: ERC20Event);
#[abi(embed_v0)]
impl ERC20Impl = ERC20Component::ERC20Impl<ContractState>;
#[abi(embed_v0)]
impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl<ContractState>;
impl ERC20InternalImpl = ERC20Component::InternalImpl<ContractState>;
#[storage]
struct Storage {
#[substorage(v0)]
erc20: ERC20Component::Storage
}
#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
ERC20Event: ERC20Component::Event
}
#[constructor]
fn constructor(
ref self: ContractState,
initial_supply: u256,
recipient: ContractAddress
) {
let name = "MyToken";
let symbol = "MTK";
self.erc20.initializer(name, symbol);
self.erc20._mint(recipient, initial_supply);
}
}DualCase dispatchers rely on Sierra's ability to catch a revert to resume execution. Currently, Starknet live chains (testnets and mainnet) don't implement that behavior. Starknet's testing framework does support it.
- Cairo book
- Cairo language documentation
- Starknet book
- Starknet documentation
- Cairo 1.0 mini-docs
- Cairopractice
Note: You can track our roadmap and future milestones in our Github Project.
OpenZeppelin Contracts for Cairo exists thanks to its contributors. There are many ways you can participate and help build high quality software, make sure to check out the contribution guide in advance.
Clone the repository:
git clone [email protected]:OpenZeppelin/cairo-contracts.gitcd into it and build:
$ cd cairo-contracts
$ scarb build
Compiling lib(openzeppelin) openzeppelin v0.10.0 (~/cairo-contracts/Scarb.toml)
Compiling starknet-contract(openzeppelin) openzeppelin v0.10.0 (~/cairo-contracts/Scarb.toml)
Finished release target(s) in 16 secondsscarb test
⚠️ Warning!⚠️ This project is still in a very early and experimental phase. It has never been audited nor thoroughly reviewed for security vulnerabilities. Do not use in production.
Refer to SECURITY.md for more details.
OpenZeppelin Contracts for Cairo is released under the MIT License.