Skip to content

Introducción a los fundamentos del programa Cairo, contrato Starknet, herramientas de desarrollo y seguridad

Notifications You must be signed in to change notification settings

alebeta06/primer_proyecto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction to Starknet Contracts

Install and get started with Starknet Foundry

  1. Then proceed with the steps to install Starknet Foundry below 👇

Steps to install Starknet Foundry

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

Confirm scarb installation by running the command:

scarb --version
  1. Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  1. Install the Starknet Foundry tool chain installer:
curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh
  1. Run the tool chain installer:
snfoundryup

Confirm Starknet Foundry installation by running:

sncast --version

or

snforge --version

Getting started with Starknet Foundry

  • Start a new project using Starknet Foundry:
snforge init HelloStarknet #project name
  • Move into the project directory
cd HelloStarknet #move into the newly created starknet foundry project directory
  • Build project
scarb build
  • Run tests
snforge test

Uses scarb to build contracts first, then proceed to run tests using snforge

  • Filter tests
snforge test test_increase
  • Run specific tests
snforge test HelloStarknet::tests::test_increase_balance --exact

Create a Starknet Account from the terminal

Use this free RPC provider: https://free-rpc.nethermind.io/sepolia-juno/

  1. Create an account contract by running this command on your terminal:

    sncast account create --url https://free-rpc.nethermind.io/sepolia-juno --name ale_dev
  2. Deploy the account contract:

    sncast account deploy --url https://free-rpc.nethermind.io/sepolia-juno --name ale_dev --fee-token eth`

NB Running the above command should trigger an error: error: Account balance is smaller than the transaction's max_fee. That why your account must be funded; to fund your account, visit - https://starknet-faucet.vercel.app/ and paste the account address that was generated on step 4 to request for testnet token.

Declare and deploy Starknet Contract

  1. Declare your contract: sncast --account ale_dev declare --url https://free-rpc.nethermind.io/sepolia-juno --fee-token eth --contract-name HelloStarknet

    Example of a contract name is Counter

  2. Deploy your contract: sncast --account ale_dev deploy --url https://free-rpc.nethermind.io/sepolia-juno --fee-token eth --class-hash 0x753505e3e0d6fdabb05de61372bf200bb9cca12cf65f8e30e61ecea35e65905


🥳🥳🥳 Congratulations on successfully deploying your first contract

Super-charge your sncast by adding a profile

This approach simplifies interactions using sncast as you can simply run commands completely eliminating the need to to add --url and --name flags whenever you want to run each sncast command: sncast --profile <name_of_profile_on_snfoundry.toml> declare --contract-name <name_of_contract_to_be_deployed> Eg: sncast -u https://free-rpc.nethermind.io/sepolia-juno/ account create -n ale_dev --add-profile ale_dev. This command automatically creates a profile for you in the root of your project directory. Meaning you will find an auto-created file named snfoundry.toml file with the following configurations:

[sncast.cohort_dev] 
account = "cohort_dev" 
accounts-file  = "~/.starknet_accounts/starknet_open_zeppelin_accounts.json" 
url = "https://free-rpc.nethermind.io/sepolia-juno/"

While deploying, make sure you check the constructor argument of the contract you are trying to deploy. All arguments must be passed in appropriately; for such case, use this command: sncast --profile <name_of_profile_on_snfoundry.toml> --class-hash <your_class_hash> --constructor-calldata <your_constructor_args>

Interacting with Deployed Contracts

  • Invoke: to execute the logic of a state-changing (writes) function within your deployed contracts from the terminal, run sncast --url https://free-rpc.nethermind.io/sepolia-juno --account ale_dev invoke --contract-address <your_contract_address> --function "<your_function_name>" --calldata 10 If you have configured your snfoundry.toml file, run: sncast --profile <your_profile> invoke --contract-address <your_contract_address> --function "<your_function_name>" --calldata <fn_args>

  • Call: to execute the logic of a non-state-changing (reads) function within your deployed contracts from the terminal, run: sncast --url https://free-rpc.nethermind.io/sepolia-juno --account cohort_dev call --contract-address <your_contract_address> --function "<your_function_name>"

NB: In the event the function to be called accepts some args, append the call --calldata flag to the above invoke and call commands with the appropriate args.

To compile your contract, run scarb build

About

Introducción a los fundamentos del programa Cairo, contrato Starknet, herramientas de desarrollo y seguridad

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages