Instalasi

The first step is to install Cairo. We'll download Cairo through starkup, a command line tool for managing Cairo versions and associated tools. You'll need an internet connection for the download.

The following steps install the latest stable version of the Cairo compiler through a binary called Scarb. Scarb bundles the Cairo compiler and the Cairo language server together in an easy-to-install package so that you can start writing Cairo code right away.

Scarb is also Cairo's package manager and is heavily inspired by Cargo, Rust's build system and package manager.

Scarb menangani banyak tugas untuk Anda, seperti membangun kode Anda (baik itu murni Cairo atau kontrak Starknet), mengunduh pustaka-pustaka yang diperlukan oleh kode Anda, membangun pustaka-pustaka tersebut, dan menyediakan dukungan LSP (Language Server Protocol) untuk ekstensi Cairo 1 pada VSCode.

Ketika Anda menulis program Cairo yang lebih kompleks, Anda mungkin akan menambahkan dependensi, dan jika Anda memulai sebuah proyek menggunakan Scarb, mengelola kode eksternal dan dependensi akan menjadi lebih mudah.

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 starkup, which will help us manage Cairo, Scarb, and Starknet Foundry.

Installing starkup on Linux or MacOs

If you're using Linux or macOS, open a terminal and enter the following command:

curl --proto '=https' --tlsv1.2 -sSf https://sh.starkup.dev | sh

The command downloads a script and starts the installation of the starkup tool, which installs the latest stable version of Cairo and related toolings. You might be prompted for your password. If the install is successful, the following line will appear:

starkup: Installation complete.

After installation, starkup will automatically install the latest stable versions of Cairo, Scarb, and Starknet Foundry. You can verify the installations by running the following commands in a new terminal session:

$ 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

$ snforge --version
snforge 0.37.0

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 memiliki ekstensi VSCode yang menyediakan penyorotan sintaks, penyelesaian kode, dan fitur-fitur berguna lainnya. Anda dapat menginstalnya dari VSCode Marketplace. Setelah terinstal, pergi ke pengaturan ekstensi, dan pastikan untuk mencentang opsi Enable Language Server dan Enable Scarb.