Setting up the environment
Overview
Setting up your local development environment to develop for Starknet involves the following steps:
Installing the prerequisites
Using a Python virtual environment is a good way to isolate your testing environment.
To create and enter the Python virtual environment, do one of the following:
Manually activating the Cairo virtual environment
Run the following two commands to manually create and activate a Cairo virtual environment:
$ python3.9 -m venv ~/cairo_venv
$ source ~/cairo_venv/bin/activate
After creating and activating the virtual environment, you should see (cairo_venv)
in the command line prompt, indicating that the virtual environment is active, for example:
(cairo_venv)
Using the Python environment manager to activate the Cairo virtual environment
Alternatively, you can use the Python environment manager to create a virtual environment:
$ curl https://pyenv.run | bash
Now add the following to your .bashrc
or .zshrc
file:
$ export PATH="$HOME/.pyenv/bin:$PATH"
$ eval "$(pyenv init -)"
$ eval "$(pyenv virtualenv-init -)"
Restart your terminal and run the following commands:
$ pyenv install 3.9.0
$ pyenv virtualenv 3.9.0 cairo_venv
$ pyenv activate cairo_venv
you should see (cairo_venv)
in the command line prompt, indicating that the virtual environment
is active, for example:
(cairo_venv)
Installing the additional dependencies
Depending on your operating system, you may need to install the following, additional dependencies:
Dependency | Description |
---|---|
|
A software development library package for the GNU Multiple Precision Arithmetic Library. |
|
(Elliptic Curve Digital Signature Algorithm) is a digital signature algorithm that is based on the mathematics of elliptic curves. |
|
An open-source software library that provides an implementation of the Elliptic Curve Digital Signature Algorithm (ECDSA) for use in cryptographic applications. It is designed to be fast, efficient, and easy to use, and is written in the Python programming language. |
|
A Python library for symbolic mathematics. |
Linux
On Ubuntu, you will need to run the following command to install the libgmp3-dev
library:
$ sudo apt install -y libgmp3-dev
macOS
On macOS, you can use Homebrew to install the gmp
library:
$ brew install gmp
After that, you need to install the ecdsa
, fastecdsa
and sympy
dependencies (Linux and Mac):
$ pip install ecdsa fastecdsa sympy
Installing the Cairo CLI
You can interact with Starknet using the Cairo command line interface. If you had a previous version of Cairo is installed, uninstall it and install the latest version:
Installing the latest version of Cairo
You can use pip
to install the latest version of Cairo:
$ pip install cairo-lang
Alternatively, you can download a specific version of Cairo using this command:
$ pip install $HOME/Downloads/cairo-lang-0.11.0.2.zip
Once you have installed the Cairo package, make sure to test your installation by running the following command:
$ starknet --version
You should see an output in your terminal similar to the below:
$ starknet 0.11.0.2
Make sure the version output matches the latest release.
Installing the Cairo compiler
The Cairo compiler allows you to compile Cairo code into Cairo VM executable byte code.
To install the Cairo compiler, run the following commands:
Cloning the repository and setting up the Cairo compiler
Go to your $HOME directory
$ cd ~/
Clone the cairo Cairo 1 compiler to a folder called .cairo in your home directory
$ git clone https://github.com/starkware-libs/cairo/ .cairo
$ cd .cairo/
$ git checkout tags/v1.0.0-alpha.6
$ cargo build --all --release
Adding the Cairo executables to your path
After building the Cairo binaries, add them to the PATH environment variable by adding the following line to your .bashrc
or .zshrc
file:
$ export PATH="$HOME/.cairo/target/release:$PATH"
Then, open a new shell and check that the following command returns a version number:
$ cairo-compile --version
Your output should look similar to the below:
$ cairo-lang-compiler 1.0.0-alpha.6
You are now able to compile, deploy and interact with smart contracts on Starknet