Deploying a smart contract

Prerequisites

Ensure Starkli and Scarb are installed correctly

Ensure that the below commands are working properly on your system.

starkli --version
scarb --version

If either of the above commands fail, please visit Setting up your environment.

Introduction

Deploying a smart contract in Starknet requires two steps:

  • Declaring the class of your contract, i.e. sending your contract’s code to the network.

  • Deploying a contract, i.e. creating an instance of the code you previously declared.

Deploying a smart contract

Deploying a smart contract involves instantiating it on Starknet. The deployment command requires the class hash of the smart contract and any arguments expected by the constructor.

For our example, the constructor expects an address to assign as the owner:

starkli deploy \
    <CLASS_HASH> \
    <CONSTRUCTOR_INPUTS> \
    --network=sepolia

With the class hash and constructor inputs, the command looks like this:

starkli deploy \
    0x00e68b4b07aeecc72f768b1c086d9b0aadce131a40a1067ffb92d0b480cf325d \
    0x02cdAb749380950e7a7c0deFf5ea8eDD716fEb3a2952aDd4E5659655077B8510 \
    --network=sepolia

Expected result

After running the command and adding your password, you will see an output similar to this:

Deploying class 0x00e68b4b07aeecc72f768b1c086d9b0aadce131a40a1067ffb92d0b480cf325d with salt 0x04bc3fc2284c8e41fb3d2a37bb0354fd0506131cc77a8c91e4e67ce3aed1d19e...
The contract will be deployed at address 0x014825acb37c36563d3b96c450afe363d2fdfa3cfbd618b323f95b68b55ebf7e
Contract deployment transaction: 0x0086972e7463d5673d8b553ae521ec2df974a97c2ce6aafc1d1c20d22c6b96c6
Contract deployed: 0x014825acb37c36563d3b96c450afe363d2fdfa3cfbd618b323f95b68b55ebf7e

The smart contract has now been deployed to Starknet.