diff --git a/src/ch01-00-getting-started.md b/src/ch01-00-getting-started.md index def9421ec..bfc75f067 100644 --- a/src/ch01-00-getting-started.md +++ b/src/ch01-00-getting-started.md @@ -5,11 +5,11 @@ Starknet is a scalable Layer-2 solution on Ethereum. This guide will walk you th We will use the Starknet Remix Plugin to compile, deploy and interact with our smart contract. It is a great tool to get started with Starknet development. 1. Visit the [Remix IDE](https://remix.ethereum.org/) website. -2. Navigate to the ‘Plugin Manager’ section in the bottom left corner. +2. Navigate to the `Plugin Manager` section in the bottom left corner. Plugin Manager -3. Activate the “Starknet” plugin. +3. Activate the `Starknet` plugin. Activate the Starknet Plugin @@ -17,10 +17,34 @@ We will use the Starknet Remix Plugin to compile, deploy and interact with our s Accept Permissions -5. After enabling, the Starknet logo appears on the left sidebar. Click it to interact with opened Cairo files. +5. After enabling, the Starknet logo appears on the left sidebar. Starknet Plugin +6. Then go to **settings** option and choose your cairo version. You can see, for now, the latest version that Remix supports is v2.4.0. + +Starknet Plugin settings + +7. Now click on the `file explorer` tab to check the sample project details. On the `Scarb.toml` file you can find the version of this sample project. + +File explorer + +8. Since Remix supports cairo v2.4.0, we have to update our `Scarb.toml` file to the same version. + +Scarb file + +## Clean your sample project + +By default we got a sample project, however on this tutorial, we plan to show the `Ownable contract` example. To acomplish this we have to edit and delete some files and directories. + +1. Rename the root directory to `ownable`. Go to your `Scarb.toml`, on [package] section, set `name` to `ownable`. +2. Delete `balance.cairo` and `forty_two.cairo` files. +3. Go to `lib.cairo` and remove all the content there. It should be empty. + +At the end, your new project should look something like this. + +Scarb file + ## Introduction to Starknet Smart Contracts The script below is a simple `Ownable` contract pattern written in Cairo for Starknet. It features: @@ -49,11 +73,11 @@ mod Ownable { #[event] #[derive(Drop, starknet::Event)] enum Event { - OwnershipTransferred1: OwnershipTransferred1, + OwnershipTransferred: OwnershipTransferred, } #[derive(Drop, starknet::Event)] - struct OwnershipTransferred1 { + struct OwnershipTransferred { #[key] prev_owner: ContractAddress, #[key] @@ -76,7 +100,7 @@ mod Ownable { self.only_owner(); let prev_owner = self.owner.read(); self.owner.write(new_owner); - self.emit(Event::OwnershipTransferred1(OwnershipTransferred1 { + self.emit(Event::OwnershipTransferred(OwnershipTransferred { prev_owner: prev_owner, new_owner: new_owner, })); @@ -105,7 +129,7 @@ The following is a brief description of the components in the contract. We will - **`starknet::ContractAddress`**: Represents a Starknet contract address. - **`OwnableTrait`**: Specifies functions for transferring and getting ownership. 2. **Events**: - - **`OwnershipTransferred1`**: Indicates ownership change with previous and new owner details. + - **`OwnershipTransferred`**: Indicates ownership change with previous and new owner details. 3. **Storage**: - **`Storage`**: Holds the contract's state with the current owner's address. 4. **Constructor**: @@ -122,12 +146,13 @@ To compile using Remix: 1. **File Creation** - Navigate to the "File Explorer" tab in Remix. - - Create a new file named `Ownable.cairo` and paste the previous [code](#cairo-example-contract) into it. + - Go to file named `lib.cairo` and paste the previous [code](#cairo-example-contract) into it. 2. **Compilation** - - Choose the `Ownable.cairo` file. - - In the "Starknet" tab, select "Compile Ownable.cairo". + - Navigate to the "Starknet" tab in Remix and click on `Home`. + - In the `1 Compile` section choose `compile a single file`. + - Click on `Compile lib.cairo`. Compilation Process @@ -146,12 +171,10 @@ Here's a step-by-step guide to deploying your smart contract on the development 1. **Select the Appropriate Network** - - In the Starknet tab, click on the top button. + - In the Starknet tab, click on the top button `Remote Devnet`. Environment selection - - Choose "Remote Devnet" for deploying your inaugural contract on a development network. - 2. **Choose a Devnet Account** - Under "Devnet account selection", a list of accounts specific to the chosen devnet is presented. @@ -172,16 +195,19 @@ Post-deployment, Remix's terminal will send various logs. These logs provide cru - `transaction_hash`: The unique hash of the transaction. This hash can be used to track the transaction's status. - `contract_address`: The address of the deployed contract. Use this address to interact with your contract. -- `calldata`: Contains the `init_owner` address fed to the constructor. +- `data`: Contains the `init_owner` address fed to the constructor. ```bash { - "transaction_hash": "0x275e6d2caf9bc98b47ba09fa9034668c6697160a74de89c4655e2a70be84247", - "contract_address": "0x5eb239955ad4c4333b8ab83406a3cf5970554b60a0d8e78a531df18c59a0db9", + "transaction_hash": "0x624f5b9f57e53f6b5b62e588f0f949442172b3ad5d04f0827928b4d12c2fa58", + "contract_address": [ + "0x699952dc736661d0ed573cd2b0956c80a1602169e034fdaa3515bfbc36d6410" + ] ... - "calldata": [ - "0x1398224729985f8e76571285c6d936b5af4a88206a1dc54c0658b4e15045292" - ], + "data": [ + "0x6b0ee6f418e47408cf56c6f98261c1c5693276943be12db9597b933d363df", + ... + ] ... } ``` @@ -207,12 +233,12 @@ With the contract now active on the development network, interaction becomes pos ```json { - "response": { + "resp": { "result": [ - "0x1398224729985f8e76571285c6d936b5af4a88206a1dc54c0658b4e15045292" + "0x6b0ee6f418e47408cf56c6f98261c1c5693276943be12db9597b933d363df" ] }, - "contract": "ownable.cairo", + "contract": "lib.cairo", "function": "get_owner" } ``` @@ -233,12 +259,12 @@ For these transactions, the terminal logs will exhibit a "status" variable, indi ```json { - "response": { + "resp": { "result": [ - "0x20884fd341e11a00b9d31600c332f126f5c3f9ffd2aa93cb43dee9f90176d4f" + "0x5495d56633745aa3b97bdb89c255d522e98fd2cb481974efe898560839aa472" ] }, - "contract": "ownable.cairo", + "contract": "lib.cairo", "function": "get_owner" } ``` diff --git a/src/img/ch01-compile-contract.png b/src/img/ch01-compile-contract.png index 08341c494..289c03eb0 100644 Binary files a/src/img/ch01-compile-contract.png and b/src/img/ch01-compile-contract.png differ diff --git a/src/img/ch01-remix-choose-devnet.png b/src/img/ch01-remix-choose-devnet.png index cae3301ee..ec6239e49 100644 Binary files a/src/img/ch01-remix-choose-devnet.png and b/src/img/ch01-remix-choose-devnet.png differ diff --git a/src/img/ch01-remix-deploy-contract.png b/src/img/ch01-remix-deploy-contract.png index 15cdf72dc..7c36aadee 100644 Binary files a/src/img/ch01-remix-deploy-contract.png and b/src/img/ch01-remix-deploy-contract.png differ diff --git a/src/img/ch01-remix-file.png b/src/img/ch01-remix-file.png index f463e83ad..486636482 100644 Binary files a/src/img/ch01-remix-file.png and b/src/img/ch01-remix-file.png differ diff --git a/src/img/ch01-remix-interact.png b/src/img/ch01-remix-interact.png index 3b7d84b03..497bd286d 100644 Binary files a/src/img/ch01-remix-interact.png and b/src/img/ch01-remix-interact.png differ diff --git a/src/img/ch01-remix-remote-devnet.png b/src/img/ch01-remix-remote-devnet.png index 2823bdfef..c948f2bda 100644 Binary files a/src/img/ch01-remix-remote-devnet.png and b/src/img/ch01-remix-remote-devnet.png differ diff --git a/src/img/ch01-remix-starknet-file-explorer.png b/src/img/ch01-remix-starknet-file-explorer.png new file mode 100644 index 000000000..c1f5dd349 Binary files /dev/null and b/src/img/ch01-remix-starknet-file-explorer.png differ diff --git a/src/img/ch01-remix-starknet-file-scarb.png b/src/img/ch01-remix-starknet-file-scarb.png new file mode 100644 index 000000000..9dba5be66 Binary files /dev/null and b/src/img/ch01-remix-starknet-file-scarb.png differ diff --git a/src/img/ch01-remix-starknet-plugin-icon.png b/src/img/ch01-remix-starknet-plugin-icon.png index 046094eaf..24474d27d 100644 Binary files a/src/img/ch01-remix-starknet-plugin-icon.png and b/src/img/ch01-remix-starknet-plugin-icon.png differ diff --git a/src/img/ch01-remix-starknet-plugin-settings.png b/src/img/ch01-remix-starknet-plugin-settings.png new file mode 100644 index 000000000..0cff01296 Binary files /dev/null and b/src/img/ch01-remix-starknet-plugin-settings.png differ diff --git a/src/img/ch01-remix-starknet-project-structure.png b/src/img/ch01-remix-starknet-project-structure.png new file mode 100644 index 000000000..a0f0ad5b3 Binary files /dev/null and b/src/img/ch01-remix-starknet-project-structure.png differ diff --git a/src/img/ch01-remix-write-interaction.png b/src/img/ch01-remix-write-interaction.png index e127f029f..2ce210571 100644 Binary files a/src/img/ch01-remix-write-interaction.png and b/src/img/ch01-remix-write-interaction.png differ