Skip to main content
If you encounter an issue while following this tutorial, see Troubleshooting.

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 the HelloStarknet 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).
If successful, the result should resemble the following:
Starknet Devnet should keep running for the following sections to work.

Fetching a predeployed account

To learn more about Starknet accounts, check out the Accounts section.
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:
This allows to avoid creating and deploying new accounts, and instead simply importing them to Starknet Foundry. To import your local node’s first predeployed account, use a new terminal window to navigate into the hello_starknet directory created in Generating HelloStarknet and run:
To learn more about sncast account import, see the Starknet Foundry documentation.
If successful, the result should resemble the following:

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 learn more about distinction between deploying a contract and declaring it, see the Cairo Book.
To declare the HelloStarknet contract, run:
If successful, the result should resemble the following:
where class_hash is the contract’s class hash, which can then be used to deploy an instance of it.
To learn more about the class hashes, check out the Cairo Book.

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.
If successful, the result should resemble the following:

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:
If successful, the result should resemble the following:
Invoking is used for write functions that modify their contract’s storage, and submits a transaction to the network that changes its state. For example, you can invoke HelloStarknet’s increase_balance function by running:
If successful, the result should resemble the following:
You can verify that your deployed contract’s storage — and by extension, the state of your local Starknet instance — has indeed changed by calling get_balance again. If all goes well, the result should resemble the following (4210=2a1642_{10} = 2a_{16}):