Skip to content

Set of scripts written in Cairo/Starknet to learn and teach newcomers the ecosystem.

License

Notifications You must be signed in to change notification settings

KaizeNodeLabs/starkiro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DARK LOGO

STARKIRO πŸ”—πŸ’‘

πŸ“– Overview

STARKIRO is a collection of educational scripts built using the Cairo programming language, specifically designed for the Starknet ecosystem. These scripts are ideal for both beginners and intermediate developers looking to deepen their understanding of Cairo and Starknet concepts.

βš™οΈ Steps to Build and Run Cairo Scripts

1. πŸ› οΈ Set Up Your Environment

  • Install Cargo

    Scarb, the official build tool for Cairo, relies on Cargo as a dependency. Cargo is included with the Rust programming language. Follow these steps to install Cargo:

    Visit the Rust installation page and follow the instructions to install Rust, which includes Cargo.

    Alternatively, use the appropriate command for your operating system

    • Linux and macOS
      curl https://sh.rustup.rs -sSf | sh
    • Windows Download and run the installer from the official Rust website.
  • Verify Cargo Installation

    Confirm that Cargo is installed by checking its version:

cargo --version
  • Install Scarb

    Please refer to the asdf documentation to install all prerequisites

    To get started, install Scarb by running the following commands in your terminal:

  asdf plugin add scarb
  asdf install scarb latest
  asdf global scarb latest
  • Verify Scarb Installation

    Confirm that Scarb is installed correctly by checking its version:

scarb --version

2. πŸ“‚ Navigate to the Scripts Directory

First, navigate to the general cairo/scripts/ directory:

cd cairo/scripts/

Then, navigate to the specific script's directory you want to run. For example, if the script you want to execute is in a folder named example_script, navigate into that directory:

cd example_script

3. πŸ—οΈ Build the Project

Build the project with the following command:

scarb build

4. πŸš€ Run the Script

To execute the main function of the script, use:

scarb cairo-run

πŸš€ Deploying Smart Contracts on Sepolia testnet using sncast

πŸ“– Overview

This guide demonstrates how to deploy a Starknet smart contract to Sepolia testnet using sncast. We'll use the SimpleHelloWorld contract as an example to walk through the entire deployment process.

βš™οΈ Steps to Deploy Your Contract

1. πŸ—οΈ Building the Contract

First, let's prepare and build our contract:

# Navigate to the contract directory
cd starknet/contracts/hello_world

# Build the contract
scarb build

# Run tests to verify everything works
scarb test

2. πŸ‘€ Account Setup

Create New Account

sncast account create \
    --url https://free-rpc.nethermind.io/sepolia-juno/v0_7 \
    --name my_deployer_account

⚠️ Important: Save the output address and max_fee information

In this case, account address : 0x03d18e21dcb1f460c287af9b84e6da83b5577569e69371d39ad3415067abdbc4

Account Creation

πŸ” View your account at: https://sepolia.starkscan.co/contract/0x03d18e21dcb1f460c287af9b84e6da83b5577569e69371d39ad3415067abdbc4

Get Test Tokens (or fund with Sepolia test tokens from existing braavos or argent x wallet )

  1. Visit Sepolia STRK Faucet
  2. Visit Sepolia ETH Faucet
  3. Request tokens for your account address
  4. Monitor on Starkscan

Deploy Account

sncast account deploy \
    --url https://free-rpc.nethermind.io/sepolia-juno/v0_7 \
    --name my_deployer_account

Account Deployment

πŸ” Track deployment: https://sepolia.starkscan.co/tx/0x073e6c7e7efea34708a73fcfdbfa5fef911e5516a5e7ea6b48814c6d4c4bd281

3. πŸ“„ Contract Deployment

Declare Contract

sncast --account my_deployer_account declare \
    --url https://free-rpc.nethermind.io/sepolia-juno/v0_7 \
    --contract-name SimpleHelloWorld

⚠️ Important: Save the class_hash from the output

Contract Declaration

Class-hash : 0x0574f6f6f9c70bbbcd08260a78653e1a21e48c4027375d2113e286883c9e513f

πŸ” Verify declaration:

Deploy Contract

sncast --account my_deployer_account deploy \
    --url https://free-rpc.nethermind.io/sepolia-juno/v0_7 \
    --class-hash 0x0574f6f6f9c70bbbcd08260a78653e1a21e48c4027375d2113e286883c9e513f

Contract Deployment

Contract deployed at address : 0x003b6059a58c96c5db118808d722f240797223900248201250e9e8b4aa34c033

πŸ” Track deployment:

4. βœ… Verifying Deployment

Set Contract Value

sncast --account my_deployer_account invoke \
    --url https://free-rpc.nethermind.io/sepolia-juno/v0_7 \
    --contract-address 0x003b6059a58c96c5db118808d722f240797223900248201250e9e8b4aa34c033 \
    --function set_hello_world

Setting Value

πŸ” View transaction: https://sepolia.starkscan.co/tx/0x076143df3b9b9341a39b205a600177f632b96b4f38430569ee3d15deb57b8466

Read Contract Value

sncast --account my_deployer_account call \
    --url https://free-rpc.nethermind.io/sepolia-juno/v0_7 \
    --contract-address 0x003b6059a58c96c5db118808d722f240797223900248201250e9e8b4aa34c033 \
    --function get_hello_world

Reading Value

The successful execution of these steps confirms your contract is properly deployed and functional on the Sepolia testnet. πŸŽ‰

βš™οΈ Steps to build and and test contracts

1. πŸ› οΈ Set Up Your Environment

  • Install Cargo

    Scarb, the official build tool for Cairo, relies on Cargo as a dependency. Cargo is included with the Rust programming language. Follow these steps to install Cargo:

    Visit the Rust installation page and follow the instructions to install Rust, which includes Cargo.

    Alternatively, use the appropriate command for your operating system

    • Linux and macOS
      curl https://sh.rustup.rs -sSf | sh
    • Windows Download and run the installer from the official Rust website.
  • Verify Cargo Installation

    Confirm that Cargo is installed by checking its version:

cargo --version

-Install asdf Before installing Scarb, you have to install asdf by following the official asdf docs

  • Verify asdf Installation

    Confirm that asdf is installed by checking its version:

asdf --version
  • Install Scarb Before you can build and test Cairo contracts, you need to have Scarb, the official build tool for Cairo. Install it with these steps:
asdf plugin add scarb
asdf install scarb latest
  • Install Starknet Foundry Install SnForge (Cairo Testing Framework) SnForge is the tool used to run unit tests for Cairo contracts in the Starknet ecosystem. Install it by running:
asdf plugin add starknet-foundry
asdf install starknet-foundry latest

2. βœ… Verify Installations

After installation, confirm that both tools are correctly installed by running:

For Scarb:

scarb --version

For SnForge:

snforge --version

3. πŸ“‚ Navigate to the Contract Directory

Proceed to the directory where your Cairo contract is located.

Example:

cd path/to/your/cairo-contract-directory

4. πŸ—οΈ Compile the Contract

Use Scarb to compile your Cairo contract by running:

scarb build

This will generate the necessary artifacts for your Cairo contract.

5. πŸƒ Run Unit Tests with SnForge

Once the contract is compiled, you can run unit tests using SnForge. .

To run your contract's tests, use the following command:

snforge test

SnForge will automatically detect the test files in your project and run them.

6. πŸ” Review Test Results

After running the tests, you will see the results in your terminal. If the tests fail, the output will include details that will help you debug the issue. If everything passes, you’ll see confirmation that your contract is working as expected.

πŸ”§ Managing Dependencies with .tool-versions

Purpose of .tool-versions

The .tool-versions file is a configuration file used by asdf to manage the versions of tools and dependencies required for each script or contract. It ensures consistency across development environments and helps avoid version mismatches.

When you navigate to a directory containing a .tool-versions file, asdf automatically switches to the specified versions of the tools listed in the file.

Example of a .tool-versions File

Here is an example of how a .tool-versions file might look:

scarb 0.5.2
cairo-lang 2.0.0

This example specifies that the project requires Scarb version 0.5.2 and Cairo version 2.0.0.

Common Errors and Warnings

If you attempt to compile a Cairo file with incorrect versions of dependencies, you may encounter an error like this:

Error: No such command `cairo-build`. Please ensure you have the correct version of Cairo installed.

To resolve this, navigate to the directory containing the .tool-versions file and run:

asdf install

This will install the correct versions of the tools specified in the .tool-versions file.

Best Practices

  • Always check the .tool-versions file in the script or contract directory before building or running.
  • Use asdf install to ensure all required dependencies are correctly installed.

Give us a star! ⭐

About

Set of scripts written in Cairo/Starknet to learn and teach newcomers the ecosystem.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published