â
It's a popular opinion that better development tools accelerate a developerâs productivity, but the arduous task lies in finding that perfect development environment.
If itâs your first time experimenting with Cairo and StarkNet, youâre probably on the hunt for this perfect tool to make your developer journey much smoother.
Thatâs why weâve written this article! Â
Weâll help you find and set up everything you need to build in StarkNet.
Cairo? âââWhatâs that?
If itâs your first time encountering StarkNet/Cairo, thereâs no need to feel lost. Weâll explain everything you need to know to get started.
StarkNet is a type of Ethereum Layer 2 scaling solution known as a ZK rollup. ZK rollups, like StarkNet, enable decentralized applications to achieve unlimited scale for their computationâââwithout compromising Ethereumâs decentralization and security, thereby solving the Scalability Trilemma.
Cairo is StarkNetâs native language and the first Turing-complete language for scripting provable programs (where one party can prove to another that a certain computation was executed correctly) for general computations.
What is a Development Environment?
A development environment is a workspace with a set of processes and programming tools to help developers efficiently build, test, and debug an application or program.
Similar to how we have a plethora of options for developing on Ethereum with solidity (Truffle, Foundry, Hardhat, etc), we also have a good amount of options for Cairo development on StarkNet. Amongst them are Protostar (developed by the Software Mansion Team), StarkNet CLI (official development framework), Nile (from the OpenZeppelin Team), and Hardhat (which is a plugin developed by ShardLabs).
But for todayâs tutorials, we will mostly play around with Protostar while using Argent X for wallet interactions and Starkscan for surfing the network.
What is Protostar?
Protostar is a development environment/toolchain for developing and testing Cairo contracts on StarkNet.
Weâve found Protostar a lot easier to set up and use among all development frameworks. There is just a single caveat. Protostar currently has no support for Windows, so windows users might have to look at setting up Windows Subsystem for Linux(WSL) in order to use Protostar or try out the other options mentioned earlier.
To get started with Protostar, you should have a git executable (>= 2.28) to be specified in the $PATH.
Installing Protostar
To install on both Windows and Linux:
1. Run the following command:
2. Restart your terminal
3. Run protostar -v to confirm the installation. If properly installed, you should see your protostar and Cairo-lang version like this:
Initializing a new Project
Protostar, similar to Truffle for solidity development, can be installed once and used for multiple projects.
To initialize a new Protostar project:
1. Run the following command:
2. It would then request the projectâs name and the libraryâs directory name. Youâd need to fill in this to initialize your project successfully.
Project Structure
As seen from the image above, initializing a new Protostar project creates a folder containing 3 new folders and a protostar.toml file.
- lib folderâââis the folder required to contain all your project dependencies
- src folderâââis the folder required to contain your contractâs source codes
- test folderâââis the folder required to contain your test files
protostar.toml
is the file which contains your command configurations. According to the official docs, it can be used to avoid passing arguments every time you run a command. Protostar searches for an argument value in the ["protostar.COMMAND_NAME"]
section, for example:
Having successfully set up Protostar, we can now easily write, compile and deploy contracts to StarkNet, but wait a minuteâŚwe would need a wallet to effectively interact with these deployed contracts, right? Thatâs where Argent X comes in to save the day!
Argent X, the wallet for StarkNet developers
Argent X is the most popular and only open-source wallet on StarkNet.
Available as a browser extension across different browsersâ web stores, Argent X helps you create, manage, and connect accounts to decentralized applications built on StarkNet.
Installing Argent X is similar to any other wallet in crypto. However, if creating a new wallet is a new process, check out our guide on how to create an Argent X wallet.
Once youâve set everything up, we will deploy and interact with a StarkNet contract.
Deploying Contracts using Protostar
Thanks to Development frameworks like Protostar, deploying Cairo contracts can be done using a few commands from the terminal.
For this tutorial, we will deploy the boilerplate contract with Protostar found in src/basic.cairo
After the 0.10.3 upgrade to the StarkNet network, deploying a contract requires declaring first, then invoking the Universal Deployer Contract passing in the declared hash as a constructor parameter.
To proceed with deployment, we will first need to compile/build the contract:
Building projects
contracts
Then we will move unto declaring the contract:
And finally, we can deploy using Protostarâs deploy command:
Once deployed, weâd get our contract address and transaction hash outputted on the screen, but how can we view and interact with this contract? Block explorers!
Become familiar with Starkscan
Similar to Etherscan on Ethereum, Starkscan is a block explorer for StarkNet, which provides a window for anyone to interact with their StarkNet contracts.
To find and interact with our Contract on StarkNet, we can simply copy the outputted contract address and head over to testnet.starkscan.co to search for the Contract.
Once the Contract has been deployed on the network, we should be able to make read/write calls to it using our Argent X wallet on Starkscan.
Writing to a StarkNet Contract
Writing to a Contract changes the Contractâs state and, as such, requires a wallet to sign and pay for transactions.
To connect your Argent X wallet to Starkscan, follow these simple steps:
1. First, click on the âConnect to Walletâ button in the âWrite Contractâ section.
2. Select âArgent Xâ
3. Finally, approve by clicking on âConnectâ
You should be able to make write calls to your StarkNet contracts.
Reading a StarkNet contract
Read calls are made to view functions. They donât alter or modify the Contract storage and can be performed without a wallet connection. For example, we could easily call the get_balance function without connecting our wallet.
Conclusion
Having reached this point, weâre confident you now have a StarkNet development Environment set up, and can easily compile, declare, deploy and interact with your Cairo Contracts.
If you have any questions as regards this, reach out to me @0xdarlington, Iâd love to help you build on StarkNet with Argent X.
For more developer resources, follow us across our socials:
Twitterâââ@argentHq
Engineering Twitterâââ@argentDeveloper
LinkedInâââ@argentHq
Youtubeâââ@argentHQ
â