You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 20, 2024. It is now read-only.
- For translations, install [gettext](https://www.gnu.org/software/gettext/): `sudo apt install gettext`.
26
27
- On Mac, you can use `brew install gettext` to install.
27
28
28
29
3.**Repository Operations**:
30
+
29
31
- Clone the main repository: `git clone https://github.com/starknet-edu/starknetbook && cd starknetbook`.
30
32
- Create and work on a branch in your fork. If you're unfamiliar, use this [guide](https://akrabat.com/the-beginners-guide-to-contributing-to-a-github-project/) for assistance.
31
33
- Once done, submit a PR to merge your edits. Ensure you tag a reviewer for feedback (`l-henri` or `@omarespejel`).
- Initiates the connection using the **`connect`** method from the **`@argent/get-starknet`** library, targeting Starknet.
80
75
- Upon a successful connection, updates the React component's state with details of the **`connection`**, **`account`**, and **`selectedAddress`**.
81
76
82
-
83
77
### `disconnectWallet`
84
78
85
79
The `disconnectWallet` function is designed to sever the connection with the web wallet asynchronously. After disconnection, it updates the component's state, resetting connection details.
- It utilizes the **`disconnect`** function, possibly from an external library, and handles the operation asynchronously with **`await`**.
97
91
- Post-disconnection, the state of the React component is updated:
98
-
-**`setConnection`** is set to **`undefined`**.
99
-
-**`setAccount`** is set to **`undefined`**.
100
-
-**`setAddress`** is cleared with an empty string.
101
-
92
+
-**`setConnection`** is set to **`undefined`**.
93
+
-**`setAccount`** is set to **`undefined`**.
94
+
-**`setAddress`** is cleared with an empty string.
102
95
103
96
### `EagerlyConnect`
104
97
105
98
The `EagerlyConnect` mechanism leverages React's `useEffect` hook to initiate a connection to Starknet upon the component's mounting or initial rendering.
- Inside the **`useEffect`**, the **`connectToStarknet`** function is defined, aiming to establish an asynchronous connection using the **`connect`** function. Parameters like **`modalMode`** and **`webWalletUrl`** are passed to guide the connection process.
123
119
- If successful in connecting (**`connection && connection.isConnected`**), the state updates with details of the connection, the account, and the selected address using **`setConnection`**, **`setAccount`**, and **`setAddress`**.
124
120
- The **`connectToStarknet`** function is executed immediately after its definition.
125
121
126
-
127
122
## Important Refresher on Smart Contract Interactions
128
123
129
124
For effective interaction with a smart contract on the network, it's crucial to understand key components after establishing a connection. Among these are the `contract address`, `ABI`, `Signer`, and `Provider`.
@@ -144,7 +139,7 @@ The Signer plays a pivotal role in:
144
139
- Signing transactions.
145
140
- Authorizing actions on the blockchain.
146
141
- Bearing the fees associated with blockchain operations.
147
-
142
+
148
143
Signers are especially linked to write operations that change the state of the blockchain. These operations need cryptographic signing for security and validity.
149
144
150
145
### Provider
@@ -157,20 +152,18 @@ The Provider acts as the medium for:
157
152
158
153
To initiate a write transaction, the connected account (signer) must be provided. This signer then signs the transaction, bearing the necessary fee for execution.
alert("You successfully decremented the counter!");
184
+
} catch (err) {
185
+
alert(err.message);
196
186
}
187
+
};
197
188
```
198
189
199
190
The **`decreaseCounter`** function is designed to interact with a smart contract and decrement a specific counter. Here's a succinct breakdown of its operation:
@@ -206,17 +197,18 @@ The **`decreaseCounter`** function is designed to interact with a smart contract
206
197
## Fetching the Current Count with `get_current_count` Function
The **`getCounter`** function is designed to retrieve the current count from a smart contract. Here's a breakdown of its operation:
@@ -229,7 +221,6 @@ The **`getCounter`** function is designed to retrieve the current count from a s
229
221
230
222
It's essential to emphasize that while performing read operations, like fetching data from a blockchain network, the function uses the provider. Unlike write operations, which typically require a signer (or an account) for transaction signing, read operations don't mandate such authentication. Thus, in this function, only the provider is specified, and not the signer.
231
223
232
-
233
224
## Wrapping It Up: Integrating a Frontend with a Counter Smart Contract
234
225
235
226
In this tutorial, we review the process of integrating a basic counter smart contract with a frontend application.
@@ -239,8 +230,8 @@ Here's a quick recap:
239
230
1.**Establishing Connection**: With the **`connectWallet`** function, we made seamless connections to the blockchain, paving the way for interactions with our smart contract.
240
231
2.**Terminating Connection**: The **`disconnectWallet`** function ensures that users can safely terminate their active connections to the blockchain, maintaining security and control.
241
232
3.**Interacting with the Smart Contract**: Using the **`increaseCounter`**, **`decreaseCounter`**, and **`getCounter`** functions, we explored how to:
242
-
- Initiate transactions
243
-
- Adjust the counter value (increment or decrement)
244
-
- Fetch data from the blockchain
233
+
- Initiate transactions
234
+
- Adjust the counter value (increment or decrement)
235
+
- Fetch data from the blockchain
245
236
246
-
For a visual walkthrough, do check out the [Basecamp frontend session](https://drive.google.com/file/d/1Dtb3Ol_BVoNV4w-_MKV8aeyyRra8nRtz/view). This comprehensive session delves deeper into the nuances of the concepts we've touched upon, presenting a mix of theoretical explanations and hands-on demonstrations.
237
+
For a visual walkthrough, do check out the [Basecamp frontend session](https://drive.google.com/file/d/1Dtb3Ol_BVoNV4w-_MKV8aeyyRra8nRtz/view). This comprehensive session delves deeper into the nuances of the concepts we've touched upon, presenting a mix of theoretical explanations and hands-on demonstrations.
Class hash declared: 0x04940154eae35788e899ceb0ef2794eaa5ea6818af5c1c726d6d278fd4979713
@@ -121,15 +119,15 @@ Class hash declared: 0x04940154eae35788e899ceb0ef2794eaa5ea6818af5c1c726d6d278fd
121
119
In cases where no modifications have been made to the provided contract, a notification will indicate that the contract has previously been declared on Starknet:
122
120
123
121
```bash
124
-
Enter keystore password:
122
+
Enter keystore password:
125
123
Not declaring class as it's already declared. Class hash: 0x04940154eae35788e899ceb0ef2794eaa5ea6818af5c1c726d6d278fd4979713
126
124
```
127
125
128
126
## Deploying the ERC20 Contract
129
127
130
128
Proceed to deploy the MKT Token using Starkli. Provide these arguments for successful deployment:
131
129
132
-
- `Initial mint`: Mint 1,000,000 tokens. Given that the MKT token comprises 18 decimals (a standard of OpenZeppelin), the input required is 1,000,000 * 10^18 or 0xd3c21bcecceda1000000. Due to the contract's expectation of a u256 mint value, provide both low and high values: 0xd3c21bcecceda1000000 and 0 respectively.
130
+
- `Initial mint`: Mint 1,000,000 tokens. Given that the MKT token comprises 18 decimals (a standard of OpenZeppelin), the input required is 1,000,000 \* 10^18 or 0xd3c21bcecceda1000000. Due to the contract's expectation of a u256 mint value, provide both low and high values: 0xd3c21bcecceda1000000 and 0 respectively.
133
131
- `Receiver address`: Use a preferred address. In this example: 0x0334863e3e851de87fb4b6b6113aa2a6b40ea20f22dbec55536e4eac912206fc
NOTE: Observe the server port that appears during launch. This will be useful for subsequent testing.
222
220
223
-
224
221
## Enhancing Your React Application with Additional Features
225
222
226
223
To enhance the app's functionality, create two components for balance and transfer. Subsequently, update the `Wallet.tsx` file to incorporate the new features:
To share your application with friends and allow them to check their balances and transfer tokens, publish your app online. Vercel offers a straightforward way to do this:
@@ -414,7 +408,6 @@ After entering your email, check your inbox and click on the "Verify" button.
Throughout this tutorial, you've walked through the steps to craft a web3 application using React and Starknet Cairo. This application, complete with an ERC20 smart contract, offers a modern web interface for user interaction. Here's a snapshot of your achievements:
459
452
460
453
- **Project Initialization**: Set up a Starknet project with Scarb and incorporated OpenZeppelin libraries.
461
-
462
454
- **Crafting the ERC20 Contract**: Developed an ERC20 token using Cairo, enriched with functionalities like balance checks and token transfers. This was then compiled and launched on the Starknet network.
463
455
464
456
- **React Application**: Built a React application powered by Starknet React, featuring components dedicated to balance inquiries and token transactions.
0 commit comments