Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/OpenZeppelin/cairo-contracts
OpenZeppelin Contracts written in Cairo for Starknet, a decentralized ZK Rollup
https://github.com/OpenZeppelin/cairo-contracts
cairo ethereum security smart-contracts starknet
Last synced: 3 months ago
JSON representation
OpenZeppelin Contracts written in Cairo for Starknet, a decentralized ZK Rollup
- Host: GitHub
- URL: https://github.com/OpenZeppelin/cairo-contracts
- Owner: OpenZeppelin
- License: mit
- Created: 2021-08-18T23:00:24.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-08T14:48:04.000Z (4 months ago)
- Last Synced: 2024-07-08T18:54:44.346Z (4 months ago)
- Topics: cairo, ethereum, security, smart-contracts, starknet
- Language: Rust
- Homepage: https://docs.openzeppelin.com/contracts-cairo
- Size: 2.31 MB
- Stars: 800
- Watchers: 18
- Forks: 322
- Open Issues: 72
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
- Library-of-Ethereum - Cairo Contracts - A library for secure smart contract development written in Cairo for StarkNet (Smart Contracts / Cairo)
- best-of-crypto - GitHub - 11% open · ⏱️ 20.05.2024): (Smart Contract Platforms)
README
# OpenZeppelin Contracts for Cairo
[![Lint and test](https://github.com/OpenZeppelin/cairo-contracts/actions/workflows/test.yml/badge.svg)](https://github.com/OpenZeppelin/cairo-contracts/actions/workflows/test.yml)
**A library for secure smart contract development** written in Cairo for [Starknet](https://starkware.co/product/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](https://docs.swmansion.com/scarb/download).
### Set up your project
Create a new project and `cd` into it.
```bash
scarb new my_project && cd my_project
```The contents of `my_project` should look like this:
```bash
$ lsScarb.toml src
```### Install the library
Edit `scarb.toml` and add:
```toml
[dependencies]
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.15.0-rc.0" }
```Build the project to download it:
```bash
$ scarb buildUpdating 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:
```cairo
#[starknet::contract]
mod MyToken {
use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl};
use starknet::ContractAddress;component!(path: ERC20Component, storage: erc20, event: ERC20Event);
// ERC20 Mixin
#[abi(embed_v0)]
impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl;
impl ERC20InternalImpl = ERC20Component::InternalImpl;#[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](https://docs.openzeppelin.com/contracts-cairo/0.15.0-rc.0/interfaces#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
- [Cairo book](https://book.cairo-lang.org/)
- [Cairo language documentation](https://docs.cairo-lang.org/)
- [Starknet book](https://book.starknet.io/)
- [Starknet documentation](https://docs.starknet.io/documentation/)
- [Cairo 1.0 mini-docs](https://github.com/Starknet-Africa-Edu/Cairo1.0)
- [Cairopractice](https://cairopractice.com/)### Tooling
- [Scarb](https://docs.swmansion.com/scarb)
## Development
> **Note**: You can track our roadmap and future milestones in our [Github Project](https://github.com/orgs/OpenZeppelin/projects/29/).
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](CONTRIBUTING.md) guide in advance.
### Set up the project
Clone the repository:
```bash
git clone [email protected]:OpenZeppelin/cairo-contracts.git
````cd` into it and build:
```bash
$ cd cairo-contracts
$ scarb buildCompiling lib(openzeppelin) openzeppelin v0.15.0-rc.0 (~/cairo-contracts/Scarb.toml)
Compiling starknet-contract(openzeppelin) openzeppelin v0.15.0-rc.0 (~/cairo-contracts/Scarb.toml)
Finished release target(s) in 16 seconds
```### Run tests
```bash
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](SECURITY.md) for more details.
## License
OpenZeppelin Contracts for Cairo is released under the [MIT License](LICENSE).