Introduction
Welcome to the third installment of the Deploy your first contract guide! 🥇 Local networks, also known as development networks or devnets, enable a fast and private development process, making them ideal for taking your first Starknet steps. This installment of the series will therefore guide you through the steps necessary to declare, deploy, and interact with theHelloStarknet contract on your very own local instance of Starknet.
Initializing a local Starknet instance
A local Starknet instance can be easily initialized using Starknet Devnet by simply running:The
--seed option is used to force consistent addresses of predeployed account (see more details below).Starknet Devnet should keep running for the following sections to work.
Fetching a predeployed account
To interact with your local Starknet instance, you first need an account. Luckily, the result of initializing a local Starknet instance using Starknet Devnet should also include a list of predeployed accounts that resembles the following:hello_starknet directory created in Generating HelloStarknet and run:
Declaring HelloStarknet locally
Before a contract can be deployed on Starknet, its compiled code needs to be submitted to the network (also known as declaring it).
To declare the HelloStarknet contract, run:
class_hash is the contract’s class hash, which can then be used to deploy an instance of it.
Deploying HelloStarknet locally
With HelloStarknet declared, you can now deploy an instance of it by running:
The
--salt option is used to force a consistent address for the deployed contract.Interacting with HelloStarknet locally
Now that your instance of HelloStarknet is deployed, you can interact with via its functions by either calling or invoking them.
Calling is used for read functions that don’t modify their contract’s storage, and allows querying a smart contract function without sending a transaction. For example, you can call HelloStarknet’s get_balance function by running:
HelloStarknet’s increase_balance function by running:
get_balance again. If all goes well, the result should resemble the following ():