Logo

Deploy Testnet Contract Tutorial

  

Note: I'm using WSL Ubuntu 22.04. If you're using Windows, refer to Windows

WARNING THAT IT'S BETTER TO USE A NEW WALLET IF YOU WANT TO TRY AND LEARN

Step 1: Installing Starkli

Install Starkli and verify the installation. The steps for installing Starkli and upgrading Starkli are identical.

                    
curl https://get.starkli.sh | sh

                

Starkliup should now be installed. Restart the terminal. Install Starkli:

                    
starkliup

                

Starkli should now be installed. Restart the terminal and run the following command to verify the installation:

                    
starkli --version

                

Expected output:

                    
Starkli version X.X.X

                

Step 2: Installing Scarb

Install Scarb and verify the installation.Restart the termina after install

                    
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh

scarb should now be installed. Restart the terminal and run the following command to verify the installation:


scarb --version

                

Expected output:

                    
Scarb version X.X.X

                

Step 3: Make a directory

Create directories for Starkli wallets.

        
mkdir .starkli-wallets
mkdir ~/.starkli-wallets/deployer
        
    

Step 4: Create a Keystore File

Create a keystore file and import your private key from Argent or Braavos:

        
starkli signer keystore from-key ~/.starkli-wallets/deployer/keystore.json

Enter private key: (your private key from Argent or Braavos)

Enter password: (your password)

Expected output:

        
Created new encrypted keystore file: /home/parallels/.starkli-wallets/deployer/keystore.json
Public key: 0x0550…
        
    

Step 5: Creating an Account Descriptor

Generate an account descriptor for your smart wallet:

        
starkli account fetch <SMART_WALLET_ADDRESS> --output ~/.starkli-wallets/deployer/account.json
        
    

Sample:

        
starkli account fetch 0x00000000000b2909291AfB0204B2092d1f36C10F4ECD38A29F79e3A3319d0000 --output ~/.starkli-wallets/deployer/account.json
        
    

Step 6: View Account Descriptor

View the account descriptor:

        
cat ~/.starkli-wallets/deployer/account.json
        
    

Step 7: Deploying an Account"Skip this step if your wallet has been deployed"

Deploy your account using the account descriptor:

        
starkli account deploy ~/.starkli-wallets/deployer/account.json
        
    

Step 8: Ensure Installation

Verify that Starkli and Scarb are installed correctly:

        
starkli --version
scarb --version
        
    

Expected output:

        
Starkli version X.X.X
Scarb version X.X.X
        
    

Step 9: Compile a Smart Contract

Create a directory with a Scarb.toml file and update it:

        
cd
scarb init
nano Scarb.toml
        
    

Insert the following code into the Scarb.toml file:

        
[package]
name = "my_contract"
version = "0.1.0"

[dependencies]
starknet = "=2.3.1"

[[target.starknet-contract]]
        
    

Step 10: Create the TEST contract

Replace the contents of ./src/lib.cairo with specific content:

Copy this sample contract code sample.


        
nano src/lib.cairo
        
    

Step 11: Compile the Smart Contract

Compile the smart contract using Scarb:

        
scarb build
        
    

The compiled contract will be saved in the target/dev/ directory. The contract is now compiled and ready to be deployed. Next you will need to declare an RPC provider within your contract.

Step 12: Declare a Smart Contract

Declare a smart contract on Starknet:

        
starkli declare target/dev/<NAME>.json --network=goerli-1 --compiler-version=2.1.0
        
    

Sample:

        
starkli declare /home/users/target/dev/my_contract_Ownable.contract_class.json --network=goerli-1 --compiler-version=2.1.0
        
    

Step 13: Deploying a Smart Contract

Deploy the smart contract with specific inputs:

        
starkli deploy <CLASS_HASH> <CONSTRUCTOR_INPUTS> --network=goerli-1
        
    

Sample input:

        
starkli deploy \
    0x05c479961b3a155df6b2468a72a823dcc89ec76898060a3e694f32a0xxxxxxxx \
    0x07ef62ac769dd7fabb2b07cc268c87dae36986fee79e9ff196920507xxxxxxxx \
    --network=goerli-1
        
    

Expected output:

        
Deploying class 0x07ef62ac769dd7fabb2b07cc268c87dae36986fee79e9ff196920507xxxxxxxx with salt 0x05c479961b3a155df6b2468a72a823dcc89ec76898060a3e694f32a0xxxxxxxx...
The contract will be deployed at address 0x0310dc277877a6a2305808dc1b72716c274f67f03af5f04a0dfb6014518464b7
Contract deployment transaction: 0x06def6fadcf26a5a86a1c3525e8c446749649dcf4fab0c9914cb4e1bea8b8890
Contract deployed:
0x0310dc277877a6a2305808dc1b72716c274f67f03af5f04a0dfb6014518464b7
        
    

Check the deployment result on StarkScan.

Starkli and Scarb

Created by: NaufalPrtm.

Official Reference Website: Starknet.

Official Reference Docs: Starknet Docs.

Reference Docs: book starknet.

Reference EDU: starknet edu.

Reference book cairo: book cairo.

Starknet Blog Starknet Blog.

Starknet OpenZeppelin Contracts OpenZeppelin Contracts for Cairo.