Code Monkey home page Code Monkey logo

cairo-contracts's Introduction

OpenZeppelin Contracts for Cairo

Lint and test

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.

Usage

Warning Expect rapid iteration. Some contracts or features are not ready to be deployed. Check the Unsupported section below.

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 = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.8.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;
    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);
    }
}

Unsupported

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.

Learn

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

Compiling lib(openzeppelin) openzeppelin v0.8.0 (~/cairo-contracts/Scarb.toml)
Compiling starknet-contract(openzeppelin) openzeppelin v0.8.0 (~/cairo-contracts/Scarb.toml)
Finished release target(s) in 16 seconds

Run tests

scarb test

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.

cairo-contracts's People

Contributors

andrew-fleming avatar martriay avatar ericnordelo avatar pscott avatar julissadantes avatar jareyes409 avatar amxx avatar orangeryang avatar koloz193 avatar juniset avatar roboteddy avatar rootulp avatar nikitastupin avatar milancermak avatar frangio avatar ca11ab1e avatar xiaolou86 avatar omahs avatar achab avatar kongtaoxing avatar rzmahmood avatar zoey-t avatar wave-95 avatar ursulafe avatar spalladino avatar 0xsachink avatar pilouche avatar enitrat avatar antazoey avatar juanigallo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.