Nile is a CLI tool to develop or interact with StarkNet projects written in Cairo. It consists of different components for developing, compiling, testing, and deploying your smart contracts and dApps, providing a CLI for executing tasks, and a Runtime Environment (NRE) for scripting.
The package is designed to be extensible and very customizable by using plugins. This guide will take you through the installation of our recommended setup, but as we expect a lot of functionality coming from plugins, you are free to customize it.
Using a sample contract, we will explore the basics of creating a Nile project. We will test it locally, deploy an account and the contract to a devnet node, and send transactions through the account to the contract.
Before installing Cairo on your machine, you need to install
sudo apt install -y libgmp3-dev # linux brew install gmp # mac
|If you have any trouble installing gmp on your Apple M1 computer, here’s a list of potential solutions.|
Some Nile dependencies have specific python version requirements. Therefore we recommend using a python version manager like pyenv, and virtual environments to avoid conflicts.
|Currently supported Python versions are >=3.8 and <3.10.|
Create a folder for your project and cd into it:
mkdir myproject && cd myproject
Create a virtualenv and activate it:
python3 -m venv env source env/bin/activate
pip install cairo-nile
nile init to quickly set up your development environment:
🗄 Creating project directory tree ⛵️ Nile project ready! Try running: nile compile
nile init creates a sample Cairo contract and test for you. Check
tests/test_contract.py for the source code.
pytest to run the test suite against the Smart Contracts:
|For a more in-deep guide on testing with parallelism and coverage, check our testing guide.|
nile compile to compile contracts under the
contracts/ folder by default.
🤖 Compiling all Cairo contracts in the contracts directory 🔨 Compiling contracts/contract.cairo ✅ Done
|For a full reference of Nile command options, check the CLI Reference section.|
By default, nile commands interacting directly with starknet nodes assume that you are using a local one if you don’t specify the network using the
--network option (default to
nile node to run a local devnet node for development.
Add an environment variable with the account’s private key to the
# .env ACCOUNT_1 = 0x1234
Don’t use this private key in production environments!
nile counterfactual-addressto precompute the deployment address of the Account contract for the given signer.
nile counterfactual-address ACCOUNT_1 --salt 123
Different salts compute to different addresses, even with the same private key.
In production, you will need to fund this address with Ether to pay for the deployment fees, which will be mandatory in testnets soon. There are multiple bridges and faucets, like Starkgate being implemented at the moment to support the developer experience.
For local development using a devnet node, you can use predeployed accounts to fund your address by using this script.
After funding the precomputed address, deploy the account using
nile setup ACCOUNT_1 --salt 123
In StarkNet, users can deploy only previously declared contracts. Openzeppelin Account is declared soon after every release in devnet, testnets and mainnet, but there could be an out-of-sync period between account update release and devnet release. Then you can declare the OZ Account using predeployed accounts through scripts.
Check Declare Account script.
First, declare the contract to register the class hash on the network. You only need to do this once as long as the contract bytecode doesn’t change.
nile declare ACCOUNT_1 contract
nile deployto deploy the contract.
nile deploy ACCOUNT_1 contract --alias my_contract
The alias option allows you to interact with the contract later without using the address.
nile call to read from a contract view function.
nile call my_contract get_balance