Getting Started


We recommend working inside a python virtual environment, but you can also install the Cairo package directly. To create and enter the virtual environment, type:

python3.7 -m venv ~/cairo_venv
source ~/cairo_venv/bin/activate

Make sure the venv is activated – you should see (cairo_venv) in the command line prompt.

Make sure you can install the following pip packages: ecdsafastecdsasympy. On Ubuntu, for example, you will have to first run:

sudo apt install -y libgmp3-dev

To install the Cairo package, run:

pip install

Cairo was tested with python3.7. To make it work with python3.6, you will have to install contextvars:

pip install contextvars

Compiling and running a Cairo program

  1. Create a file, named test.cairo, with the following lines:
func main():
    [ap] = 1000; ap++
    [ap] = 2000; ap++
    [ap] = [ap - 2] + [ap - 1]; ap++
  1. Compile: (make sure all commands are executed in the virtual environment)
cairo-compile test.cairo \
  --debug_info \
  --prime=3618502788666131213697322783095070105623107215331596699973092056135872020481 \
  --output test_compiled.json
  1. Run:
cairo-run \
  --program=test_compiled.json --print_output \
  --print_info --relocate_prints
  1. You can open the Cairo tracer by providing the --tracer flag to cairo-run. Then open it at http://localhost:8100/.

Visual Studio Code setup

Install the Cairo Visual Studio Code extension:

code --install-extension cairo-0.0.1.vsix

Configure Visual Studio Code settings:

"editor.formatOnSaveTimeout": 1500