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
Copy file name to clipboardExpand all lines: versioned_docs/version-0.12/miden-tutorials/web-client/counter_contract_tutorial.md
+59-52Lines changed: 59 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,8 +3,6 @@ title: 'Incrementing the Count of the Counter Contract'
3
3
sidebar_position: 5
4
4
---
5
5
6
-
# Incrementing the Count of the Counter Contract
7
-
8
6
_Using the Miden WebClient to interact with a custom smart contract_
9
7
10
8
## Overview
@@ -22,7 +20,7 @@ Using a script, we will invoke the increment function within the counter contrac
22
20
23
21
- Node `v20` or greater
24
22
- Familiarity with TypeScript
25
-
-`pnpm`
23
+
-`yarn`
26
24
27
25
This tutorial assumes you have a basic understanding of Miden assembly. To quickly get up to speed with Miden assembly (MASM), please play around with running basic Miden assembly programs in the [Miden playground](https://0xmiden.github.io/examples/).
28
26
@@ -31,7 +29,7 @@ This tutorial assumes you have a basic understanding of Miden assembly. To quick
To run the code above in our frontend, run the following command:
266
275
267
276
```
268
-
pnpm run dev
277
+
yarn dev
269
278
```
270
279
271
280
Open the browser console and click the button "Increment Counter Contract".
@@ -345,13 +354,11 @@ end
345
354
346
355
**Note**: _It's a good habit to add comments below each line of MASM code with the expected stack state. This improves readability and helps with debugging._
347
356
348
-
### Concept of function visibility and modifiers in Miden smart contracts
349
-
350
-
The `export.increment_count` function in our Miden smart contract behaves like an "external" Solidity function without a modifier, meaning any user can call it to increment the contract's count. This is because it calls `account::incr_nonce` during execution. For internal procedures, use the `proc` keyword as opposed to `export`.
357
+
### Authentication Component
351
358
352
-
If the `increment_count` procedure did not call the `account::incr_nonce` procedure during its execution, only the deployer of the counter contract would be able to increment the count of the smart contract (if the RpoFalcon512 component was added to the account, in this case we didn't add it).
359
+
**Important**: All accounts must have an authentication component. For smart contracts that do not require authentication (like our counter contract), we use a `NoAuth` component.
353
360
354
-
In essence, if a procedure performs a state change in the Miden smart contract, and does not call `account::incr_nonce` at some point during its execution, this function can be equated to having an `onlyOwner` Solidity modifer, meaning only the user with knowledge of the private key of the account can execute transactions that result in a state change.
361
+
This `NoAuth` component allows any user to interact with the smart contract without requiring signature verification.
355
362
356
363
**Note**: _Adding the `account::incr_nonce` to a state changing procedure allows any user to call the procedure._
357
364
@@ -373,8 +380,8 @@ To run a full working example navigate to the `web-client` directory in the [mid
@@ -277,8 +279,8 @@ export async function createMintConsume(): Promise<void> {
277
279
278
280
```bash
279
281
cd miden-web-app
280
-
npm i
281
-
npm run dev
282
+
yarn install
283
+
yarn dev
282
284
```
283
285
284
286
Open [http://localhost:3000](http://localhost:3000) in your browser, click **Tutorial #1: Create a wallet and deploy a faucet**, and check the browser console (F12 or right-click → Inspect → Console):
0 commit comments