Second part of a series of tutorials on how to use the StarkNet Hardhat Plugin for Cairo smart contract development.
Hello again frens! 👋
In our previous tutorial (tutorial Part 1) you may have noticed that doing this on the testnet can be slow 😞
But don't worry - in this tutorial Part 2, we will show you how to do the same operations, but on a local instance of the StarkNet network, called the devnet!
If you already have installed starknet-devnet before, make sure you have the latest version with. Check that with:
If not, you can download it by running:
For devnet device specific and installation in general check here.
In this tutorial we are going to deploy our contract on Devnet, so to make that possible, open a new terminal, and then run
--seed 0 ensures the creation of the same pre-deployed accounts each time.
From the output should see that we have a bunch of pre-deployed accounts with funds in them:
Account #0
Address: 0x7e00d496e324876bbc8531f2d9a82bf154d1a04a50218ee74cdd372f75a551a
Public key: 0x7e52885445756b313ea16849145363ccb73fb4ab0440dbac333cf9d13de82b9
Private key: 0xe3e70682c2094cac629f6fbed82c07cd
Account #1
Address: 0x69b49c2cc8b16e80e86bfc5b0614a59aa8c9b601569c7b80dde04d3f3151b79
Public key: 0x175666e92f540a19eb24fa299ce04c23f3b75cb2d2332e3ff2021bf6d615fa5
Private key: 0xf728b4fa42485e3a0a5d2f346baa9455
Etc …
We’ll use one of those accounts to deploy and interact with our contracts.
First and foremost let’s configure our hardhat.config file in our project, to be able to connect to the local devnet.
The config file should now look like this.
In the console, write this command:
From the tutorial Part 1, you can use the already compiled hello.cairo contract!
Note: there is a convenient difference in Part 2 with this step, compering to Part 1 tutorial. Because Devnet gives us 10 already pre-deployed accounts, we don’t need to go through all the same steps! We can skip the declaration and deployments of accounts!
We’ll just use Account #0 from the devnet output to deploy our contract and interact with it! Let’s add a new file to our project and name it quick-script.ts. We can then copy the following code to it:
Finally, we run the script with:
…which will declare, deploy and make some calls to the contract.
Hooray! You did it!
You can see that the contract was deployed to the local network Devnet and we made some other transactions as well, getting the balance and increasing balance!
And that’s it! Congratulations again! 😃
Also be sure to check out the hardhat-example repository for more examples on features and usage!
There will be more tutorials, so make sure you follow our blog and Twitter.
Happy coding!🚀🚀🚀
*This article is also available on SpaceShard Medium.