Skip to content

Cheat sheet

Get started with Scarb by following a cheatsheet of the most important commands.

Creating new project

shell
scarb new project/directory

TIP

There is scarb init which runs in current directory instead of creating new one.

Compiling

shell
scarb build

Built Sierra code of this package will be written to target/dev directory.

TIP

scarb clean cleans target directory.

TIP

scarb check checks for errors without compiling the packages.

Building CASM

Add following to Scarb.toml:

toml
[lib]
casm = true

Adding following line to [lib] section will stop building Sierra code:

toml
sierra = false

Building StarkNet contracts

Add following to Scarb.toml:

toml
[dependencies]
starknet = ">=2.5.4"

[[target.starknet-contract]]

Adding dependencies

In manifest

Add dependency hosted on a Git repository:

toml
[dependencies]
alexandria_math = { git = "https://github.com/keep-starknet-strange/alexandria.git" }

Add dependency located in local path:

toml
[dependencies]
alexandria_math = { path = "../path-to-alexandria-checkout/alexandria" }

TIP

You can add version field to specify package version requirement.

TIP

You can add branch, tag and rev fields to Git dependencies.

TIP

You can use ssh:// URLs, Scarb uses local git installation for all network operations.

TIP

You can add development dependencies in [dev-dependencies] section.

Via scarb add

Add dependency hosted on a Git repository:

shell
scarb add alexandria_math --git https://github.com/keep-starknet-strange/alexandria.git

Add dependency located in local path:

shell
scarb add alexandria_math --path ../path-to-alexandria-checkout/alexandria

TIP

You can specify package version like this: [email protected], but see remarks in previous section.

TIP

--git supports --branch, --tag and --rev arguments.

TIP

scarb rm removes a dependency.

TIP

--dev flag adds/removes a development dependency.

Formatting

Format Cairo code:

shell
scarb fmt

Check formatting in CI:

shell
scarb fmt -c

Updating locked dependencies

shell
scarb update