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
title: "Incrementing the Count of the Counter Contract"
2
+
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
8. Calls `sys::truncate_stack` to truncate the stack to size 16.
288
308
289
309
```masm
290
-
use.miden::account
310
+
use.miden::active_account
311
+
use miden::native_account
291
312
use.std::sys
292
313
293
314
const.COUNTER_SLOT=0
@@ -298,7 +319,7 @@ export.get_count
298
319
push.COUNTER_SLOT
299
320
# => [index]
300
321
301
-
exec.account::get_item
322
+
exec.active_account::get_item
302
323
# => [count]
303
324
304
325
# clean up stack
@@ -312,7 +333,7 @@ export.increment_count
312
333
push.COUNTER_SLOT
313
334
# => [index]
314
335
315
-
exec.account::get_item
336
+
exec.active_account::get_item
316
337
# => [count]
317
338
318
339
add.1
@@ -323,7 +344,7 @@ export.increment_count
323
344
push.COUNTER_SLOT
324
345
# [index, count+1]
325
346
326
-
exec.account::set_item
347
+
exec.native_account::set_item
327
348
# => [OLD_VALUE]
328
349
329
350
dropw
@@ -333,13 +354,11 @@ end
333
354
334
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._
335
356
336
-
### Concept of function visibility and modifiers in Miden smart contracts
337
-
338
-
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
339
358
340
-
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**: Starting with Miden Client 0.10.0, all accounts must have an authentication component. For smart contracts that don't require authentication (like our counter contract), we use a `NoAuth` component.
341
360
342
-
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.ivate key of the account can execute transactions that result in a state change.
343
362
344
363
**Note**: _Adding the `account::incr_nonce` to a state changing procedure allows any user to call the procedure._
345
364
@@ -361,8 +380,8 @@ To run a full working example navigate to the `web-client` directory in the [mid
361
380
362
381
```bash
363
382
cd web-client
364
-
pnpm i
365
-
pnpm run start
383
+
yarn install
384
+
yarn start
366
385
```
367
386
368
387
### Resetting the `MidenClientDB`
@@ -376,6 +395,6 @@ The Miden webclient stores account and note data in the browser. If you get erro
0 commit comments