Deploying and interacting with the HelloStarknet
contract on Starknet Sepolia
If you encounter an issue while following this tutorial, check out "Hello, Starknet!" quickstart tutorial troubleshooting. |
Introduction
Welcome to the fourth installment of the "Hello, Starknet!" quickstart series, the official tutorial for starting your journey as a Starknet developer! 🚀
Starknet Sepolia is Starknet’s testnet environment designed to provide developers with a testing ground that mirrors the behavior of the Starknet Mainnet while being connected to the Ethereum Sepolia testnet, making it ideal for debugging and optimizing your code before deploying it to production. This installment of the series will therefore guide you through the steps necessary to deploy and interact with the HelloStarknet
contract on Starknet Sepolia.
Deploying a new Sepolia account
Similar to interacting with a Starknet Devnet instance, to interact with Starknet Sepolia you first need an account. However, instead fetching a predeployed Sepolia account, we will create a new account and deploy it using sncast
ourselves.
To learn how to fetch a predeployed Sepolia account, check out Troubleshooting. |
To create the account’s information (private key, address, etc.), navigate into the hello_starknet
directory created in Generating HelloStarknet
and run:
sncast account create \
--network=sepolia \
--name=sepolia
When run, the command shows instructions on how to prefund the account before proceeding, which can be done using the Starknet Sepolia faucet.
Prefunding the account is required because deploying an account involves sending a |
Once your account is funded, you can deploy it by running:
sncast account deploy \
--network sepolia \
--name sepolia
If successful, the output of should resemble the following:
command: account deploy
transaction_hash: 0x01340c0328b037bab85d53dd1b3b8040b0e0f4be58a42a94f554c9bf6e5bf30d
To see invocation details, visit:
transaction: https://sepolia.starkscan.co/tx/0x01340c0328b037bab85d53dd1b3b8040b0e0f4be58a42a94f554c9bf6e5bf30d
Deploying HelloStarknet
on Sepolia
Unlike when using a Starknet Devnet instance, there’s no need for us to declare HelloStarknet
on Sepolia as it has already been declared before (remember: declaration is a one-time process for each unique contract code). To verify that, you can try declaring it by navigating into the hello_starknet
directory created in Generating HelloStarknet
, running:
sncast --account=sepolia declare \
--contract-name=HelloStarknet \
--network=sepolia
The result should resemble to the following:
command: declare
error: Transaction execution error = TransactionExecutionErrorData { transaction_index: 0, execution_error: Message("Class with hash 0x051e0d3b26fb79035afdc64d2214eb18291629b4f2ef132e79c3f3fbe1ba57c4 is already declared.") }
With HelloStarknet
already declared, you can deploy an instance of it by running:
sncast --account=sepolia deploy \
--class-hash=0x051e0d3b26fb79035afdc64d2214eb18291629b4f2ef132e79c3f3fbe1ba57c4 \
--network=sepolia
If successful, the result should resemble the following:
command: deploy
contract_address: 0x05fe561f0907f61b1099ba64ee18a5250606d43d00d4f296ba622d287ceb2538
transaction_hash: 0x0723a63261d2df60f571df8a2b8c8c64694278aae66481a0584445c03234d83f
To see deployment details, visit:
contract: https://sepolia.starkscan.co/contract/0x05fe561f0907f61b1099ba64ee18a5250606d43d00d4f296ba622d287ceb2538
transaction: https://sepolia.starkscan.co/tx/0x0723a63261d2df60f571df8a2b8c8c64694278aae66481a0584445c03234d83f
Your deployed contract’s address will be different the than one listed above. Make sure to use the address of your own deployed contract in the following section. |
Interacting with HelloStarknet
on Sepolia
Once your instance of HelloStarknet
is deployed, you can invoke its increase_balance
function by running:
sncast --account=sepolia invoke \
--contract-address=0x05fe561f0907f61b1099ba64ee18a5250606d43d00d4f296ba622d287ceb2538 \
--function=increase_balance \
--arguments=66 \
--network=sepolia
If successful, the result should resemble the following:
command: invoke
transaction_hash: 0x02b900ba6bfb6a7d256d34c5d3a895abbfa0805d23f80253958e101069700020
To see invocation details, visit:
transaction: https://sepolia.starkscan.co/tx/0x02b900ba6bfb6a7d256d34c5d3a895abbfa0805d23f80253958e101069700020
Once the invoke transaction is accepted on Starknet Sepolia, you can call your deployed contract’s get_balance
function to confirm that your deployed contract’s storage — and by extension, the state of Starknet Sepolia — has indeed changed, by running:
sncast call \
--contract-address=0x05fe561f0907f61b1099ba64ee18a5250606d43d00d4f296ba622d287ceb2538 \
--function=get_balance \
--network=sepolia
If all goes well, the result should resemble the following (6610 = 4216
):
command: call
response: [0x42]