Built with auditless/cairo-template
A minimal template for building smart contracts with Cairo 1.0 using the Quaireaux project defaults.
- No submodules, forks or other heavy machinery
- Uses the
cairo-test-runner
binary for running tests - Built as a Scarb package for reusability and uses Scarb dependencies for libraries
- Has reproducible builds using GitHub Actions
- Uses Scarb scripts natively for custom commands
- Includes advanced debugging views like the Sierra intermediate representation
Step 1: Install Cairo 1.0 (guide by Abdel)
If you are on an x86 Linux system and able to use the release binary, you can download Cairo here https://github.com/starkware-libs/cairo/releases.
For everyone, else, we recommend compiling Cairo from source like so:
# Install stable Rust
$ rustup override set stable && rustup update
# Clone the Cairo compiler in $HOME/Bin
$ cd ~/Bin && git clone git@github.com:starkware-libs/cairo.git && cd cairo
# OPTIONAL/RECOMMENDED: If you want to install a specific version of the compiler
# Fetch all tags (versions)
git fetch --all --tags
# View tags (you can also do this in the cairo compiler repository)
git describe --tags `git rev-list --tags`
# Checkout the version you want
git checkout tags/v1.0.0-alpha.6
# Generate release binaries
$ cargo build --all --release
NOTE: Keeping Cairo up to date
Now that your Cairo compiler is in a cloned repository, all you will need to do is pull the latest changes and rebuild as follows:
$ cd ~/Bin/cairo && git fetch && git pull && cargo build --all --release
export PATH="$HOME/Bin/cairo/target/release:$PATH"
NOTE: If installing from a Linux binary, adapt the destination path accordingly.
This will make available several binaries. The one we use is called cairo-test
.
Follow the installation guide in Scarb's Repository.
- Disable previous Cairo 0.x extension
- Install the Cairo 1 extension for proper syntax highlighting and code navigation. Just follow the steps indicated here.
From Step 1, the cairo-language-server
binary should be built and executing this command will copy its path into your clipboard.
$ which cairo-language-server | pbcopy
Update the languageServerPath
of the Cairo 1.0 extension by pasting the path.
First you will need to clone the repository or click the Use this template
button
at the top of the page to create a new repository based on the template.
Next, you will want to update the configuration files with the name of your project:
├── .cairo_project.toml
└── .Scarb.toml
The Cairo template currently supports building and testing contracts.
Build the contracts.
$ scarb build
Run the tests in src/test
:
$ scarb run test
Format the Cairo source code (using Scarb):
$ scarb fmt
View the compiled Sierra output of your Cairo code:
$ scarb run sierra
- The Quaireaux team for coming up with this configuration and especially Abdel for helping me with Cairo 1.0 installation
- Paul Berg and the foundry-template project which served as inspiration
- Last but not least, the StarkWare team for building the first smart contract language that is a joy to use
- ArgentX template is built as a fork of the compiler
- Eni's cairo1-template uses git submodules for installation
- Shramee's Starklings use the cairo1 crates as libraries and builds its own framework