Instalación
Cairo puede instalarse simplemente descargando Scarb. Scarb incluye el compilador Cairo y el servidor de lenguaje Cairo en un paquete fácil de instalar para que puedas empezar a escribir código Cairo inmediatamente.
Scarb es el gestor de paquetes de Cairo y está fuertemente inspirado en Cargo, el sistema de construcción y gestor de paquetes de Rust.
Scarb se encarga de muchas tareas por ti, como construir tu código (ya sea en Cairo puro o contratos Starknet), descargar las librerias necesarias para tu código, construir esas librerias y proporcionar soporte LSP (Language Server Protocol) para la extensión de Cairo 1 en VSCode.
A medida que escribas programas Cairo más complejos, es posible que añadas dependencias, y si comienzas un proyecto utilizando Scarb, gestionar elcódigo externo y las dependencias será mucho más fácil de hacer.
Starknet Foundry is a toolchain for Cairo programs and Starknet smart contract development. It supports many features, including writing and running tests with advanced features, deploying contracts, interacting with the Starknet network, and more.
Let's start by installing Scarb and Starknet Foundry.
Instalando Scarb
Requisitos
Scarb requiere un ejecutable Git disponible en la variable de entorno PATH
.
Instalación
To install Scarb, please refer to the installation instructions. We strongly recommend that you install Scarb via asdf, a CLI tool that can manage multiple language runtime versions on a per-project basis. This will ensure that the version of Scarb you use to work on a project always matches the one defined in the project settings, avoiding problems related to version mismatches.
Please refer to the asdf documentation to install all prerequisites.
Once you have asdf installed locally, you can download Scarb plugin with the following command:
asdf plugin add scarb
This will allow you to download specific versions:
asdf install scarb 2.9.2
and set a global version:
asdf global scarb 2.9.2
Otherwise, you can simply run the following command in your terminal, and follow the onscreen instructions. This will install the latest stable release of Scarb.
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh
In both cases, you can verify installation by running the following command in a new terminal session, it should print both Scarb and Cairo language versions, e.g:
$ scarb --version
scarb 2.9.2 (5070ff374 2024-12-11)
cairo: 2.9.2 (https://crates.io/crates/cairo-lang-compiler/2.9.2)
sierra: 1.6.0
Installing Starknet Foundry
To install Starknet Foundry, please refer to the installation instructions. We also recommend that you install it via asdf.
Once installed, you can run the following command to see the version:
$ snforge --version
snforge 0.35.1
We'll describe Starknet Foundry in more detail in Chapter 10 for Cairo programs testing and in Chapter 18 when discussing Starknet smart contract testing and security in the second part of the book.
Installing the VSCode Extension
Cairo tiene una extensión VSCode que proporciona resaltado de sintaxis, cairo1). Una vez instalada, ve a la configuración de la extensión, y asegúrate de marcar las opciones Enable Language Server
y Enable Scarb
options."