From 08401adb0764459cb94223174477f4e9ac912745 Mon Sep 17 00:00:00 2001 From: Strong Force <64266194+princeibs@users.noreply.github.com> Date: Tue, 15 Oct 2024 09:03:43 +0100 Subject: [PATCH] Update README.md --- README.md | 125 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 84 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index ba75ed3..3195454 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,102 @@ ## Introduction to Starknet Contracts -1. Install starknet-foundry by running this command: - `curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh` +### Install and get started with Starknet Foundry +#### Environment Set up (Only when you are using Github Codespaces) +1. Go to Github Codespaces: [https://github.com/codespaces](https://github.com/codespaces) +2. Create a blank Codespace by selecting the "Blank" template: ![image](https://github.com/user-attachments/assets/e8c4b537-245d-46d1-a238-10daa3e20b6a) +3. Then proceed with the steps to install Starknet Foundry below 👇 + +Steps to install Starknet Foundry +1. Install Scarb: +```bash +curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh +``` +Confirm scarb installation by running the command: +```bash +scarb --version +``` -2. Restart your terminal - run `snfoundryup` +2. Install Rust +```bash +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh +``` -3. Use this free RPC provider: https://free-rpc.nethermind.io/sepolia-juno/ +3. Install the Starknet Foundry tool chain installer: +```bash +curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh +``` +4. Run the tool chain installer: +```bash +snfoundryup +``` +Confirm Starknet Foundry installation by running: +```bash +sncast --version +``` +or +```bash +snforge --version +``` -4. Create an account contract by running this command on your terminal: - `sncast account create --url https://free-rpc.nethermind.io/sepolia-juno --name cohort_dev` +### Getting started with Starknet Foundry +- Start a new project using Starknet Foundry: +```bash +snforge init hello_starknet #project name +``` +- Move into the project directory +```bash +cd hello_starknet #move into the newly created starknet foundry project directory +``` +- Build project +```bash +scarb build +``` +- Run tests +``` +snforge test +``` +> Uses `scarb` to build contracts first, then proceed to run tests using `snforge` +- Filter tests +```bash +snforge test test_increase_ +``` +- Run specific tests +```bash +snforge test hello_starknet::tests::test_increase_balance --exact +``` + +### Create a Starknet Account from the terminal -5. Deploy the account contract: - `sncast account deploy --url https://free-rpc.nethermind.io/sepolia-juno --name cohort_dev --fee-token eth` +> Use this free RPC provider: https://free-rpc.nethermind.io/sepolia-juno/ + +1. Create an account contract by running this command on your terminal: + ```bash + sncast account create --url https://free-rpc.nethermind.io/sepolia-juno --name cohort_dev + ``` + +2. Deploy the account contract: + ```bash + sncast account deploy --url https://free-rpc.nethermind.io/sepolia-juno --name cohort_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. -6. Compile your contract by running: - `scarb build` - - -> If you get an error like `scarb: command not found`, then it means you don't have scarb installed. To install scarb, run this command in your terminal `curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh`. You can checkout the full guide [here](https://docs.swmansion.com/scarb/download.html) - -7. Declare your contract: +### Declare and deploy Starknet Contract +1. Declare your contract: `sncast --account cohort_dev declare --url https://free-rpc.nethermind.io/sepolia-juno --fee-token eth --contract-name Counter` > Example of a contract name is `Counter` - - -8. Deploy your contract: +2. Deploy your contract: `sncast --account cohort_dev deploy --url https://free-rpc.nethermind.io/sepolia-juno --fee-token eth --class-hash 0x70eef4488bd1858900685210e5afb64d827e6e2bebfd85b01ff8b46d4584471` +--- +🥳🥳🥳 Congratulations on successfully deploying your first contract +--- - -🥳🥳🥳 You have successfully deployed your first contract - -Alternatively, you can create a `snfoundry.toml` with the following config: - -``` -[sncast.deploy_dev] -account = "deploy_dev" -accounts-file = "~/.starknet_accounts/starknet_open_zeppelin_accounts.json" -url = "https://free-rpc.nethermind.io/sepolia-juno/" -``` - -##### Super-charge your `sncast` by adding a profile +### 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 declare --contract-name ` Eg: `sncast -u https://free-rpc.nethermind.io/sepolia-juno/ account create -n cohort_dev --add-profile cohort_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: @@ -61,20 +110,14 @@ 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 --class-hash --constructor-calldata ` ---- - - - ---- - -##### Interacting with Deployed Contracts +### Interacting with Deployed Contracts -- Invoke: to execute the logic of a state-changing (writes) function within your deployed contracts from the terminal, run +- **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 cohort_dev invoke --contract-address --function "" --calldata 10` If you have configured your `snfoundry.toml` file, run: `sncast --profile invoke --contract-address --function "" --calldata ` -- Call: to execute the logic of a non-state-changing (reads) function within your deployed contracts from the terminal, run: +- **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 --function ""` NB: