Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.

Commit 223c1f9

Browse files
committed
📝 run prettier
1 parent eea107d commit 223c1f9

File tree

6 files changed

+101
-131
lines changed

6 files changed

+101
-131
lines changed

.github/workflows/mdbook.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
publish:
1818
runs-on: ubuntu-latest
1919
permissions:
20-
contents: read # To push a branch
20+
contents: read # To push a branch
2121
id-token: write # To update the deployment status
2222
steps:
2323
- name: Checkout
@@ -49,4 +49,4 @@ jobs:
4949

5050
- name: scp upload to production site
5151
run: |
52-
sshpass -p ${{ secrets.PROD_PASS }} scp -o 'StrictHostKeyChecking no' -r public_html/ ${{ secrets.PROD_USER }}@${{ secrets.PROD_IP }}:~/
52+
sshpass -p ${{ secrets.PROD_PASS }} scp -o 'StrictHostKeyChecking no' -r public_html/ ${{ secrets.PROD_USER }}@${{ secrets.PROD_IP }}:~/

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ cargo install mdbook --version 0.4.31 && cargo install mdbook-i18n-helpers --ver
2222
```
2323

2424
2. **Machine Packages**:
25+
2526
- For translations, install [gettext](https://www.gnu.org/software/gettext/): `sudo apt install gettext`.
2627
- On Mac, you can use `brew install gettext` to install.
2728

2829
3. **Repository Operations**:
30+
2931
- Clone the main repository: `git clone https://github.com/starknet-edu/starknetbook && cd starknetbook`.
3032
- 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.
3133
- Once done, submit a PR to merge your edits. Ensure you tag a reviewer for feedback (`l-henri` or `@omarespejel`).

src/ch02-07-01-00-counter-ui.md

Lines changed: 53 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,19 @@ In `index.js`, several key functions are provided:
3939

4040
```javascript
4141
// Connect to the blockchain via a wallet provider (argentX or Bravoos)
42-
const connectWallet = async() => {
43-
}
42+
const connectWallet = async () => {};
4443

4544
// Terminate the connection
46-
const disconnectWallet = async() => {
47-
}
45+
const disconnectWallet = async () => {};
4846

4947
// Trigger increment
50-
const increaseCounter = async() => {
51-
}
48+
const increaseCounter = async () => {};
5249

5350
// Trigger decrement
54-
const decreaseCounter = async() => {
55-
}
51+
const decreaseCounter = async () => {};
5652

5753
// Retrieve current count
58-
const getCounter = async() => {
59-
}
54+
const getCounter = async () => {};
6055
```
6156

6257
## Managing Connection
@@ -79,7 +74,6 @@ const connectWallet = async() => {
7974
- Initiates the connection using the **`connect`** method from the **`@argent/get-starknet`** library, targeting Starknet.
8075
- Upon a successful connection, updates the React component's state with details of the **`connection`**, **`account`**, and **`selectedAddress`**.
8176

82-
8377
### `disconnectWallet`
8478

8579
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.
@@ -95,35 +89,36 @@ const disconnectWallet = async() => {
9589

9690
- It utilizes the **`disconnect`** function, possibly from an external library, and handles the operation asynchronously with **`await`**.
9791
- 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.
10295

10396
### `EagerlyConnect`
10497

10598
The `EagerlyConnect` mechanism leverages React's `useEffect` hook to initiate a connection to Starknet upon the component's mounting or initial rendering.
10699

107100
```javascript
108101
useEffect(() => {
109-
const connectToStarknet = async() => {
110-
const connection = await connect({ modalMode: "neverAsk", webWalletUrl: "https://web.argent.xyz" });
111-
112-
if(connection && connection.isConnected) {
113-
setConnection(connection);
114-
setAccount(connection.account);
115-
setAddress(connection.selectedAddress);
116-
}
102+
const connectToStarknet = async () => {
103+
const connection = await connect({
104+
modalMode: "neverAsk",
105+
webWalletUrl: "https://web.argent.xyz",
106+
});
107+
108+
if (connection && connection.isConnected) {
109+
setConnection(connection);
110+
setAccount(connection.account);
111+
setAddress(connection.selectedAddress);
117112
}
118-
connectToStarknet();
119-
}, [])
113+
};
114+
connectToStarknet();
115+
}, []);
120116
```
121117

122118
- 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.
123119
- 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`**.
124120
- The **`connectToStarknet`** function is executed immediately after its definition.
125121

126-
127122
## Important Refresher on Smart Contract Interactions
128123

129124
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:
144139
- Signing transactions.
145140
- Authorizing actions on the blockchain.
146141
- Bearing the fees associated with blockchain operations.
147-
142+
148143
Signers are especially linked to write operations that change the state of the blockchain. These operations need cryptographic signing for security and validity.
149144

150145
### Provider
@@ -157,20 +152,18 @@ The Provider acts as the medium for:
157152

158153
To initiate a write transaction, the connected account (signer) must be provided. This signer then signs the transaction, bearing the necessary fee for execution.
159154

160-
161155
## Invoking the `increment` Function
162156

163157
```javascript
164-
const increaseCounter = async() => {
165-
try {
166-
const contract = new Contract(contractAbi, contractAddress, account)
167-
await contract.increment()
168-
alert("You successfully incremented the counter!")
169-
}
170-
catch(err) {
171-
alert(err.message)
172-
}
158+
const increaseCounter = async () => {
159+
try {
160+
const contract = new Contract(contractAbi, contractAddress, account);
161+
await contract.increment();
162+
alert("You successfully incremented the counter!");
163+
} catch (err) {
164+
alert(err.message);
173165
}
166+
};
174167
```
175168

176169
The **`increaseCounter`** function is crafted to interact with a smart contract and increment a specific counter. Here's a step-by-step breakdown:
@@ -180,20 +173,18 @@ The **`increaseCounter`** function is crafted to interact with a smart contract
180173
3. On successful execution, the user receives a confirmation alert indicating the counter's increment.
181174
4. In case of any errors during the process, an alert displays the corresponding error message to the user.
182175

183-
184176
## Invoking the `decrement` Function
185177

186178
```javascript
187-
const decreaseCounter = async() => {
188-
try {
189-
const contract = new Contract(contractAbi, contractAddress, account)
190-
await contract.decrement()
191-
alert("You successfully decremented the counter!")
192-
}
193-
catch(err) {
194-
alert(err.message)
195-
}
179+
const decreaseCounter = async () => {
180+
try {
181+
const contract = new Contract(contractAbi, contractAddress, account);
182+
await contract.decrement();
183+
alert("You successfully decremented the counter!");
184+
} catch (err) {
185+
alert(err.message);
196186
}
187+
};
197188
```
198189

199190
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
206197
## Fetching the Current Count with `get_current_count` Function
207198

208199
```javascript
209-
const getCounter = async() => {
210-
const provider = new Provider({ sequencer: { network:constants.NetworkName.SN_MAIN } })
211-
try {
212-
const mycontract = new Contract(contractAbi, contractAddress, provider)
213-
const num = await mycontract.get_current_count()
214-
setRetrievedValue(num.toString())
215-
}
216-
catch(err) {
217-
alert(err.message)
218-
}
200+
const getCounter = async () => {
201+
const provider = new Provider({
202+
sequencer: { network: constants.NetworkName.SN_MAIN },
203+
});
204+
try {
205+
const mycontract = new Contract(contractAbi, contractAddress, provider);
206+
const num = await mycontract.get_current_count();
207+
setRetrievedValue(num.toString());
208+
} catch (err) {
209+
alert(err.message);
219210
}
211+
};
220212
```
221213

222214
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
229221

230222
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.
231223

232-
233224
## Wrapping It Up: Integrating a Frontend with a Counter Smart Contract
234225

235226
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:
239230
1. **Establishing Connection**: With the **`connectWallet`** function, we made seamless connections to the blockchain, paving the way for interactions with our smart contract.
240231
2. **Terminating Connection**: The **`disconnectWallet`** function ensures that users can safely terminate their active connections to the blockchain, maintaining security and control.
241232
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
245236

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.

src/ch02-07-01-01-erc20-ui.md

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ The example will walk through creating an ERC20 token named MKT and crafting a w
1313

1414
<img alt="Basic Dapp ERC20" src="img/ch02-basic-dapp-screenshot.png" class="center" style="width: 75%;" />
1515

16-
1716
Throughout this guide, the following tools and libraries will be utilized:
1817

1918
- Scarb 0.7.0 with Cairo 2.2.0
@@ -104,15 +103,14 @@ scarb build
104103

105104
Subsequent to the compilation, declare the smart contract on the Starknet testnet:
106105

107-
108106
```bash
109107
starkli declare target/dev/erc20_erc20.sierra.json --account ../../demo-account.json --keystore ../../demo-key.json --compiler-version 2.1.0 --network goerli-1 --watch
110108
```
111109

112110
The output should appear similar to:
113111

114112
```bash
115-
Enter keystore password:
113+
Enter keystore password:
116114
Declaring Cairo 1 class: 0x04940154eae35788e899ceb0ef2794eaa5ea6818af5c1c726d6d278fd4979713
117115
... [shortened for brevity]
118116
Class hash declared: 0x04940154eae35788e899ceb0ef2794eaa5ea6818af5c1c726d6d278fd4979713
@@ -121,15 +119,15 @@ Class hash declared: 0x04940154eae35788e899ceb0ef2794eaa5ea6818af5c1c726d6d278fd
121119
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:
122120

123121
```bash
124-
Enter keystore password:
122+
Enter keystore password:
125123
Not declaring class as it's already declared. Class hash: 0x04940154eae35788e899ceb0ef2794eaa5ea6818af5c1c726d6d278fd4979713
126124
```
127125
128126
## Deploying the ERC20 Contract
129127
130128
Proceed to deploy the MKT Token using Starkli. Provide these arguments for successful deployment:
131129
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.
133131
- `Receiver address`: Use a preferred address. In this example: 0x0334863e3e851de87fb4b6b6113aa2a6b40ea20f22dbec55536e4eac912206fc
134132

135133
```bash
@@ -139,7 +137,7 @@ starkli deploy 0x04940154eae35788e899ceb0ef2794eaa5ea6818af5c1c726d6d278fd497971
139137
The output should appear similar to:
140138

141139
```bash
142-
Enter keystore password:
140+
Enter keystore password:
143141
... [shortened for brevity]
144142
Contract deployed: 0x001892d81e09cb2c2005f0112891dacb92a6f8ce571edd03ed1f3e549abcf37f
145143
```
@@ -220,15 +218,14 @@ npm run dev
220218
221219
NOTE: Observe the server port that appears during launch. This will be useful for subsequent testing.
222220
223-
224221
## Enhancing Your React Application with Additional Features
225222
226223
To enhance the app's functionality, create two components for balance and transfer. Subsequently, update the `Wallet.tsx` file to incorporate the new features:
227224
228225
<img alt="Basic Dapp ERC20 React Files" src="img/ch02-basic-dapp-react-files.png" class="center" style="width: 75%;" />
229226
230-
231227
### Balance Component
228+
232229
Design a balance component inside `components/Balance.tsx` and integrate the following code:
233230
234231
```typescript
@@ -257,7 +254,7 @@ function Balance() {
257254
</div>
258255
);
259256
}
260-
257+
261258
export default Balance;
262259
```
263260
@@ -276,7 +273,7 @@ function Transfer() {
276273
const [count] = useState(1);
277274
const [recipient, setRecipient] = useState('0x');
278275
const [amount, setAmount] = useState('1000000000000000000');
279-
276+
280277
const calls = useMemo(() => {
281278
const tx = {
282279
contractAddress: '0x001892d81e09cb2c2005f0112891dacb92a6f8ce571edd03ed1f3e549abcf37f',
@@ -287,7 +284,7 @@ function Transfer() {
287284
}, [address, count, recipient, amount]);
288285
289286
const { write } = useContractWrite({ calls });
290-
287+
291288
return (
292289
<>
293290
<p>Transfer:</p>
@@ -310,7 +307,6 @@ export default Transfer;
310307
311308
NOTE: Replace contractAddress with the address of your deployed contract.
312309
313-
314310
### Updating the Wallet Component
315311
316312
Proceed to modify the `components/Wallet.tsx` file. Replace any existing content with the following enhanced code:
@@ -367,7 +363,6 @@ export default function WalletBar() {
367363
368364
This updated code refines the Wallet component to offer a more interactive experience for users intending to connect or manage their wallets.
369365
370-
371366
## Finalizing the MKT Token Application
372367
373368
To finalize the application setup, we need the ABI file for the MKT token. Follow the steps below to generate and integrate it:
@@ -386,7 +381,6 @@ Well done! The basic MKT token application is now operational locally. Access it
386381
387382
<img alt="Localhost" src="img/ch02-basic-dapp-localhost.png" class="center" style="width: 75%;" />
388383
389-
390384
## Deploying Your Project Online
391385
392386
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.
414408
415409
<img alt="Vercel verify" src="img/ch02-basic-dapp-vercel-verify.png" class="center" style="width: 75%;" />
416410
417-
418411
On successful verification, you'll receive a confirmation in the console.
419412
420413
4. Link your project to Vercel:
@@ -441,15 +434,15 @@ Congratulations! Your MKT token web3 application is now accessible to everyone.
441434
442435
Engage with your app by:
443436
444-
* Connecting your wallet:
437+
- Connecting your wallet:
445438
446439
<img alt="Vercel publication 2" src="img/ch02-basic-dapp-pub2.png" class="center" style="width: 75%;" />
447440
448-
* Checking your balance:
441+
- Checking your balance:
449442
450443
<img alt="Vercel publication 3" src="img/ch02-basic-dapp-pub3.png" class="center" style="width: 75%;" />
451444
452-
* Transferring tokens:
445+
- Transferring tokens:
453446
454447
<img alt="Vercel publication 4" src="img/ch02-basic-dapp-pub4.png" class="center" style="width: 75%;" />
455448
@@ -458,7 +451,6 @@ Engage with your app by:
458451
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:
459452
460453
- **Project Initialization**: Set up a Starknet project with Scarb and incorporated OpenZeppelin libraries.
461-
462454
- **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.
463455
464456
- **React Application**: Built a React application powered by Starknet React, featuring components dedicated to balance inquiries and token transactions.

0 commit comments

Comments
 (0)