Skip to content

Latest commit

 

History

History
79 lines (58 loc) · 3.26 KB

2.deploy-nile.md

File metadata and controls

79 lines (58 loc) · 3.26 KB

Testnet

Starknet-devnet is a Flask wrapper of Starknet state. Similar in purpose to Ganache. Aims to mimic Starknet's Alpha testnet, but with simplified functionality.

Nile is a Manager developed by OpenZeppelin for your Cairo projects. If you are a Python Developer, this is your tool.

If you want to test a Cairo project:

# mkdir nile-test
# cd nile-test
# python3.9 -m venv env
# source env/bin/activate
(env) # pip3 install starknet-devnet
(env) # pip3 install cairo-nile
(env) # nile init
(env) # mv contracts/contract.cairo contracts/contract1.cairo

Start your devnet in a different terminal

# source env/bin/activate
(env) # nile node

Now you have a Starknet node running in the background and a few private keys loaded with devnet tokens.

Note : This command creates the project directory structure and installs cairo-lang, starknet-devnet, pytest, and pytest-asyncio for you. The template includes a makefile to build the project (make build) and run tests (make test).

In contracts you have contract.cairo with a basic Cairo contract with two functions : increase_balance and get_balance. Let's deploy and test. The name of the contract is contract, but we need an alias for it: stark1

(env) # nile compile
(env) # nile deploy contract1 --alias stark1

You get the transaction Hash, and the info on the deployed contracts gets saved to localhost.deployments.txt (address:abiFile:alias).

Ready to play!

(env) # nile call stark1 get_balance

Congrats, you just did your first interaction with a Starknet contract :)

In order to write to any Smart Contract we need an Account, and it does not work like any other EVM Blockchain.

Introduction to accounts

In Cairo there are no Externally Owned Accounts (EOA), they deploy a Smart Contract representing an account with its own logic: The signature scheme that controls who can issue transactions from it) A bit more complex but by far more powerful to have full control of addresses: delegation, recovery, blocking...

Will go deeper into Accounts here, but for now, you can test accounts also with Nile.

Firs create you need to create a .env file in the root of your cairo-test directory. You can use one of the private Keys provided by your devnet (nile node).

(env) # echo "PKEY=0xcd978ef14f70de2242c40fdfce5947e6" >> .env
(env) # nile setup PKEY

The Addres of stark1 can be found in localhost.deployments.txt and also the address and the alias of your new Account (account-0).

Interacting with your contract

Now you are ready to send a transaction to the contract stark1 from your new Account

(env) # nile send PKEY stark1 increase_balance 20
Calling increase_balance on stark1 with params: ['20']
Invoke transaction was sent.
(env) # nile call stark1 get_balance
20

Resources