Skip to content
This repository has been archived by the owner on Sep 25, 2024. It is now read-only.

Latest commit

 

History

History
94 lines (67 loc) · 3.67 KB

2. Setting up a development Environment.md

File metadata and controls

94 lines (67 loc) · 3.67 KB

Setting up a development Environment for Cairo 1.0

Having done a brief introduction to Cairo and Starknet, we are going to be moving unto getting familiar with Cairo 1.0. But before we delve into writing Cairo, we'll need to set up a development Environment for writing, compiling and deploying our Starknet contracts!

What is a Development Environment?

A development environment is a workspace with a set of processes and programming tools to help developers efficiently build, test, and debug an application or program.

Similar to how we have a plethora of options for developing on Ethereum with Solidity (Truffle, Foundry, Hardhat, etc), we also have a good amount of options for Cairo development on StarkNet. Amongst them are Protostar/Scarb (developed by the Software Mansion Team), Cairo-lang (official development framework), Nile (from the OpenZeppelin Team), and Hardhat (which is a plugin developed by ShardLabs).

At the time of this writing, Scarb and Cairo-lang are the most efficient frameworks for Cairo 1.0 development, so we are going to use the Cairo-lang framework for the purpose of this guide.

Prerequisites

In order to install and use the Cairo-lang framework effectively, you'd need to have Rust and Python3.9.0 installed. You could check out the installation guides below:

  1. Rust
  2. Python 3.9.0

Having installed these, we'll move forward to setting up a virtual python environment.

Setting up a virtual environment

Python's virtual environment enables you install libraries and scripts, that are isolated from those installed in other virtual environments and on your system environment. We recommend working inside a virtual environment whilst working with Cairo-lang.

To create and enter a virtual environment, use the command below:

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

Alternatively you could use pyenv.

Installations

Having setup our virtual environment, we are going to install a few packages before finally installing Cairo-lang:

For Ubuntu users:

    sudo apt install -y libgmp3-dev
    pip install ecdsa fastecdsa sympy

For Mac users:

    brew install gmp
    pip install ecdsa fastecdsa sympy

Then we can now finally install Cairo-lang using pip:

    pip install cairo-lang

PS: If you had a previous version of Cairo-lang installed, ensure to uninstall it before running the installation command. To uninstall, simply run:

    pip uninstall cairo-lang

To confirm installation run the command below:

    starknet --version

If installation was successful, you should see the Cairo-lang version displayed.

Compiler Setup

To complete our environment setup, we'd need some certain executables like cairo-compile, starknet-compile etc. To get this we'd do a little engineering:

Firstly change directory to Home, and clone the main cairo repository:

    cd ~/
    git clone https://github.com/starkware-libs/cairo/ .cairo

Then checkout to the working branch and generate the release binaries:

    cd .cairo/
    git checkout tags/v1.0.0-alpha.6
    cargo build --all --release

Finally, we are going to add this generated binaries as executables to our path (.bashrc or .zshrc):

    export PATH="$HOME/.cairo/target/release:$PATH"

To confirm if this process was successful, open a new terminal and run the command below:

    cairo-compile --version

You should have your compiler version outputted on the terminal if everything works as expected!

Having setup our development environment, we can now delve into Cairo!