A minimal template for building smart contracts with Cairo 1.0

Overview

Minimal Cairo 1.0 Template PRs Welcome License: MIT CI Badge

Built with auditless/cairo-template

A minimal template for building smart contracts with Cairo 1.0 using the Quaireaux project defaults.

How it works

  • 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

Installing dependencies

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 [email protected]: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

Step 2: Add Cairo 1.0 executables to your path

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.

Step 3: Install the Cairo package manager Scarb

Follow the installation guide in Scarb's Repository.

Step 4: Setup Language Server

VS Code Extension

  • Disable previous Cairo 0.x extension
  • Install the Cairo 1 extension for proper syntax highlighting and code navigation. Just follow the steps indicated here.

Cairo Language Server

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.

How to use this template

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

Working with your project

The Cairo template currently supports building and testing contracts.

Build

Build the contracts.

$ scarb build

Test

Run the tests in src/test:

$ scarb run test

Format

Format the Cairo source code (using Scarb):

$ scarb fmt

Sierra (advanced)

View the compiled Sierra output of your Cairo code:

$ scarb run sierra

Thanks to

  • 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

Other templates

License

MIT © Auditless Limited

You might also like...
My code for the terra.academy course on CosmWasm smart contracts

CosmWasm Starter Pack This is a template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it. To understan

Smart contracts powering Spectrum Protocol on Terra

Spectrum Core Contracts This monorepository contains the source code for the core smart contracts implementing Spectrum Protocol on the Terra blockcha

Create your personal token with rust smart contracts

Solana Rust Token 💰 This application written Rust using Anchor ⚓

This is a node implementation of Thippy, a Substrate parachain for smart contracts

Thippy ‒- A Smart Contracts Parachain This is a node implementation of Thippy, a Substrate parachain for smart contracts. Developing Smart Contracts f

Rust library for build smart contracts on Internet Computer, by the Spinner.Cash team.

Spinner Rust library for building smart contracts on the Internet Computer. More specifically it is used by Spinner.Cash, a decentralized layer-2 prot

Rust implementation for Thippy -- a Substrate parachain for smart contracts.

Thippy ‒- A Smart Contracts Parachain This is a node implementation of Thippy, a Substrate parachain for smart contracts. Developing Smart Contracts f

Helpful functions and macros for developing smart contracts on NEAR Protocol.

near-contract-tools Helpful functions and macros for developing smart contracts on NEAR Protocol. This package is a collection of common tools and pat

CLI for Stellar Smart Contracts.

stellar-contract-cli CLI for running Stellar contracts locally in a test VM. Executes WASM files built using the rs-stellar-contract-sdk. Install carg

A gRPC-based scripting library for interacting with CosmWasm smart-contracts.

Cosmos Rust Script Smart contract scripting library to ease CosmWasm smart contract development and deployment. cosm-script is inspired by terra-rust-

Comments
  • Instruct users to checkout specific Cairo version instead of HEAD

    Instruct users to checkout specific Cairo version instead of HEAD

    In Step 1: Install Cairo 1.0, the instructions make users checkout Cairo HEAD and thus build latest main instead of a specific language version, which they do expect.

    I think what is missing is to add a line on how to check out git tag after this line in provided snippet:

    $ cd ~/Bin && git clone [email protected]:starkware-libs/cairo.git && cd cairo
    

    This is needed especially, because if the user is not fluent with Git, will not notice this and will probably end up with core mismatch panic in the compiler.

    opened by mkaput 1
  • Add a comment in Scarb config showing how Quaireaux library could be added (as a git dependency)

    Add a comment in Scarb config showing how Quaireaux library could be added (as a git dependency)

    • Scarb now supports git dependencies
    • Add a commented out Quaireaux library that people could uncomment and install to use in their projects
    • Since this is a minimal template we shouldn't install any libraries by default
    good first issue 
    opened by Pet3ris 0
  • Find out a better way to keep CI Cairo dependency up to date

    Find out a better way to keep CI Cairo dependency up to date

    Currently we have to manually override the artifact every time Cairo releases a new version. This could become cleaner if StarkWare decide to publish Mac binaries so may not need to action right now.

    opened by Pet3ris 0
Owner
Auditless
Auditless
A template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it.

CosmWasm Starter Pack This is a template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it. To understan

null 1 Mar 7, 2022
🖨 Template for Rust applications & smart contracts @okp4.

Rust Template Template for Rust projects @okp4. Purpose & Philosophy This repository holds the template for building Rust projects with a consistent s

OKP4 – Open Knowledge Protocol For 6 Nov 17, 2022
Minimal template for simulating contracts with arbiter.

arbiter-template Minimal template for simulating contracts with arbiter. Usage Clone this repository git clone https://github.com/primitivefinance/arb

Primitive 28 Aug 15, 2023
Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana (WIP) ⛏👷🚧⚠️

Solana BPF Boilerplate Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana This boilerplate provides the following. Si

ono 6 Jan 30, 2022
evm2near compiles Solidity contracts into NEAR WebAssembly contracts.

EVM → NEAR evm2near is a project for compiling EVM bytecode into wasm bytecode, with the particular goal of having that wasm artifact be executable on

Aurora 125 Dec 3, 2022
Ticketed Discreet Log Contracts (DLCs) to enable instant buy-in for wager-like contracts on Bitcoin.

dlctix Ticketed Discreet Log Contracts (DLCs) to enable instant buy-in for wager-like contracts on Bitcoin. This project is part of the Backdrop Build

null 7 Feb 29, 2024
Smart contracts for Ref Finance

Ref Finance Contracts This mono repo contains the source code for the smart contracts of Ref Finance on NEAR. Contracts Contract Reference Description

Ref Finance 92 Dec 7, 2022
Skyward Finance smart-contracts

Build and Init ./build.sh near dev-deploy res/skyward.was export CONTRACT_ID=skyward.testnet near call $CONTRACT_ID new --account_id=$CONTRACT_ID Regi

Skyward Finance 777 Jan 4, 2023
Rust client to Opensea's APIs and Ethereum smart contracts

opensea.rs Rust bindings & CLI to the Opensea API and Contracts CLI Usage Run cargo r -- --help to get the top level help menu: opensea-cli 0.1.0 Choo

Georgios Konstantopoulos 226 Dec 27, 2022
A framework for creating PoC's for Solana Smart Contracts in a painless and intuitive way

Solana PoC Framework DISCLAIMER: any illegal usage of this framework is heavily discouraged. Most projects on Solana offer a more than generous bug bo

Neodyme 165 Dec 18, 2022