Skip to content

OpenZeppelin/cairo-contracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

a8610bb · Feb 18, 2025
Feb 14, 2025
Feb 3, 2025
Feb 18, 2025
Aug 2, 2024
Jan 20, 2025
Sep 18, 2024
Sep 29, 2023
Oct 8, 2024
Sep 29, 2023
Feb 5, 2025
Nov 14, 2024
Nov 15, 2024
Jan 15, 2025
Nov 27, 2023
Feb 3, 2025
Oct 29, 2024
Jul 30, 2024
Dec 6, 2024
Dec 17, 2024
Aug 29, 2024
Feb 5, 2025
Sep 10, 2022

Repository files navigation

OpenZeppelin Contracts for Cairo

Lint and test

A library for secure smart contract development written in Cairo for Starknet, a decentralized ZK Rollup.

Tip

🧙 Not sure how to get started? Check out Contracts Wizard for Cairo — an interactive smart contract generator.

Usage

Warning

This repo contains highly experimental code. It hasn't been audited. Use at your own risk.

Prepare the environment

Simply install Cairo and scarb.

Set up your project

Create a new project and cd into it.

scarb new my_project && cd my_project

The contents of my_project should look like this:

$ ls

Scarb.toml src

Install the library

Edit scarb.toml and add:

[dependencies]
openzeppelin = "0.20.0"

The previous example would import the entire library. We can also add each package as a separate dependency to improve the building time by not including modules that won't be used:

[dependencies]
openzeppelin_token = "0.20.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 seconds

Using the library

Open 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, ERC20HooksEmptyImpl, DefaultConfig};
    use starknet::ContractAddress;

    component!(path: ERC20Component, storage: erc20, event: ERC20Event);

    // ERC20 Mixin
    #[abi(embed_v0)]
    impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl<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);
    }
}

Learn

Documentation

Check out the full documentation site!

Cairo

Tooling

Development

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.

Set up the project

Clone the repository:

git clone [email protected]:OpenZeppelin/cairo-contracts.git

cd into it and build:

cd cairo-contracts
scarb build -w

Run tests

snforge test -w

Security

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.

License

OpenZeppelin Contracts for Cairo is released under the MIT License.