Skip to content

Commit cd7a959

Browse files
authored
Merge pull request #101 from 0xMiden/keinberger/v12-webclient-fixes
chore(web-client): implement final fixes for v12 snapshot
2 parents 70a4cc9 + 7c71ab2 commit cd7a959

File tree

8 files changed

+193
-121
lines changed

8 files changed

+193
-121
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"singleQuote": true,
5+
"trailingComma": "all"
6+
}

versioned_docs/version-0.12/miden-tutorials/web-client/about.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Web Client"
2+
title: 'Web Client'
33
sidebar_position: 1
44
---
55

versioned_docs/version-0.12/miden-tutorials/web-client/counter_contract_tutorial.md

Lines changed: 59 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ title: 'Incrementing the Count of the Counter Contract'
33
sidebar_position: 5
44
---
55

6-
# Incrementing the Count of the Counter Contract
7-
86
_Using the Miden WebClient to interact with a custom smart contract_
97

108
## Overview
@@ -22,7 +20,7 @@ Using a script, we will invoke the increment function within the counter contrac
2220

2321
- Node `v20` or greater
2422
- Familiarity with TypeScript
25-
- `pnpm`
23+
- `yarn`
2624

2725
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/).
2826

@@ -31,7 +29,7 @@ This tutorial assumes you have a basic understanding of Miden assembly. To quick
3129
1. Create a new Next.js app with TypeScript:
3230

3331
```bash
34-
npx create-next-app@latest miden-web-app --typescript
32+
yarn create next-app@latest miden-web-app --typescript
3533
```
3634

3735
Hit enter for all terminal prompts.
@@ -44,7 +42,7 @@ This tutorial assumes you have a basic understanding of Miden assembly. To quick
4442

4543
3. Install the Miden WebClient SDK:
4644
```bash
47-
pnpm i @demox-labs/miden-sdk@0.12.3
45+
yarn add @demox-labs/miden-sdk@0.12.3
4846
```
4947

5048
**NOTE!**: Be sure to add the `--webpack` command to your `package.json` when running the `dev script`. The dev script should look like this:
@@ -87,7 +85,9 @@ export default function Home() {
8785
onClick={handleIncrementCounterContract}
8886
className="w-full px-6 py-3 text-lg cursor-pointer bg-transparent border-2 border-orange-600 text-white rounded-lg transition-all hover:bg-orange-600 hover:text-white"
8987
>
90-
{isIncrementCounter ? 'Working...' : 'Tutorial #3: Increment Counter Contract'}
88+
{isIncrementCounter
89+
? 'Working...'
90+
: 'Tutorial #3: Increment Counter Contract'}
9191
</button>
9292
</div>
9393
</div>
@@ -135,54 +135,56 @@ export async function incrementCounterContract(): Promise<void> {
135135

136136
// Counter contract code in Miden Assembly
137137
const counterContractCode = `
138-
use.miden::active_account
139-
use miden::native_account
140-
use.std::sys
138+
use.miden::active_account
139+
use miden::native_account
140+
use.std::sys
141141
142-
const.COUNTER_SLOT=0
142+
const.COUNTER_SLOT=0
143143
144-
#! Inputs: []
145-
#! Outputs: [count]
146-
export.get_count
147-
push.COUNTER_SLOT
148-
# => [index]
144+
#! Inputs: []
145+
#! Outputs: [count]
146+
export.get_count
147+
push.COUNTER_SLOT
148+
# => [index]
149149
150-
exec.active_account::get_item
151-
# => [count]
150+
exec.active_account::get_item
151+
# => [count]
152152
153-
# clean up stack
154-
movdn.4 dropw
155-
# => [count]
156-
end
153+
# clean up stack
154+
movdn.4 dropw
155+
# => [count]
156+
end
157157
158-
#! Inputs: []
159-
#! Outputs: []
160-
export.increment_count
161-
push.COUNTER_SLOT
162-
# => [index]
158+
#! Inputs: []
159+
#! Outputs: []
160+
export.increment_count
161+
push.COUNTER_SLOT
162+
# => [index]
163163
164-
exec.active_account::get_item
165-
# => [count]
164+
exec.active_account::get_item
165+
# => [count]
166166
167-
add.1
168-
# => [count+1]
167+
add.1
168+
# => [count+1]
169169
170-
debug.stack
170+
debug.stack
171171
172-
push.COUNTER_SLOT
173-
# [index, count+1]
172+
push.COUNTER_SLOT
173+
# [index, count+1]
174174
175-
exec.native_account::set_item
176-
# => [OLD_VALUE]
175+
exec.native_account::set_item
176+
# => [OLD_VALUE]
177177
178-
dropw
179-
# => []
180-
end
178+
dropw
179+
# => []
180+
end
181181
`;
182182

183183
// Building the counter contract
184184
// Counter contract account id on testnet
185-
const counterContractId = AccountId.fromHex('0xe59d8cd3c9ff2a0055da0b83ed6432');
185+
const counterContractId = AccountId.fromHex(
186+
'0xe59d8cd3c9ff2a0055da0b83ed6432',
187+
);
186188

187189
// Reading the public state of the counter contract from testnet,
188190
// and importing it into the WebClient
@@ -200,9 +202,11 @@ end
200202
const storageMap = new StorageMap();
201203
const storageSlotMap = StorageSlot.map(storageMap);
202204

203-
const mappingAccountComponent = AccountComponent.compile(counterContractCode, builder, [
204-
storageSlotMap,
205-
]).withSupportsAllTypes();
205+
const mappingAccountComponent = AccountComponent.compile(
206+
counterContractCode,
207+
builder,
208+
[storageSlotMap],
209+
).withSupportsAllTypes();
206210

207211
const walletSeed = new Uint8Array(32);
208212
crypto.getRandomValues(walletSeed);
@@ -238,10 +242,15 @@ end
238242
`;
239243

240244
const txScript = builder.compileTxScript(txScriptCode);
241-
const txIncrementRequest = new TransactionRequestBuilder().withCustomScript(txScript).build();
245+
const txIncrementRequest = new TransactionRequestBuilder()
246+
.withCustomScript(txScript)
247+
.build();
242248

243249
// Executing the transaction script against the counter contract
244-
await client.submitNewTransaction(counterContractAccount.id(), txIncrementRequest);
250+
await client.submitNewTransaction(
251+
counterContractAccount.id(),
252+
txIncrementRequest,
253+
);
245254

246255
// Sync state
247256
await client.syncState();
@@ -265,7 +274,7 @@ end
265274
To run the code above in our frontend, run the following command:
266275

267276
```
268-
pnpm run dev
277+
yarn dev
269278
```
270279

271280
Open the browser console and click the button "Increment Counter Contract".
@@ -345,13 +354,11 @@ end
345354

346355
**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._
347356

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
351358

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.
353360

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.
355362

356363
**Note**: _Adding the `account::incr_nonce` to a state changing procedure allows any user to call the procedure._
357364

@@ -373,8 +380,8 @@ To run a full working example navigate to the `web-client` directory in the [mid
373380

374381
```bash
375382
cd web-client
376-
pnpm i
377-
pnpm run start
383+
yarn install
384+
yarn start
378385
```
379386

380387
### Resetting the `MidenClientDB`

versioned_docs/version-0.12/miden-tutorials/web-client/create_deploy_tutorial.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
---
2-
title: 'Creating Accounts and Faucets'
2+
title: 'Creating Accounts and Deploying Faucets'
33
sidebar_position: 2
44
---
55

6-
## Creating Accounts and Deploying Faucets
7-
86
_Using the Miden WebClient in TypeScript to create accounts and deploy faucets_
97

108
## Overview
@@ -22,7 +20,7 @@ In this tutorial, we'll build a simple Next.js application that demonstrates the
2220

2321
- Node `v20` or greater
2422
- Familiarity with TypeScript
25-
- `pnpm`
23+
- `yarn`
2624

2725
## Public vs. private accounts & notes
2826

@@ -42,7 +40,7 @@ It is useful to think of notes on Miden as "cryptographic cashier's checks" that
4240
1. Create a new Next.js app with TypeScript:
4341

4442
```bash
45-
npx create-next-app@latest miden-web-app --typescript
43+
yarn create next-app@latest miden-web-app --typescript
4644
```
4745

4846
Hit enter for all terminal prompts.
@@ -55,7 +53,7 @@ It is useful to think of notes on Miden as "cryptographic cashier's checks" that
5553

5654
3. Install the Miden WebClient SDK:
5755
```bash
58-
pnpm install @demox-labs/miden-sdk@0.12.3
56+
yarn add @demox-labs/miden-sdk@0.12.3
5957
```
6058

6159
**NOTE!**: Be sure to add the `--webpack` command to your `package.json` when running the `dev script`. The dev script should look like this:
@@ -96,7 +94,7 @@ export async function createMintConsume(): Promise<void> {
9694
);
9795

9896
// Connect to Miden testnet RPC endpoint
99-
const nodeEndpoint = 'https://rpc.testnet.miden.io:443';
97+
const nodeEndpoint = 'https://rpc.testnet.miden.io';
10098
const client = await WebClient.createClient(nodeEndpoint);
10199

102100
// 1. Sync with the latest blockchain state
@@ -142,7 +140,9 @@ export default function Home() {
142140
onClick={handleCreateMintConsume}
143141
className="w-full px-6 py-3 text-lg cursor-pointer bg-transparent border-2 border-orange-600 text-white rounded-lg transition-all hover:bg-orange-600 hover:text-white"
144142
>
145-
{isCreatingNotes ? 'Working...' : 'Tutorial #1: Create a wallet and deploy a faucet'}
143+
{isCreatingNotes
144+
? 'Working...'
145+
: 'Tutorial #1: Create a wallet and deploy a faucet'}
146146
</button>
147147
</div>
148148
</div>
@@ -170,7 +170,7 @@ export async function createMintConsume(): Promise<void> {
170170
"@demox-labs/miden-sdk"
171171
);
172172

173-
const nodeEndpoint = 'https://rpc.testnet.miden.io:443';
173+
const nodeEndpoint = 'https://rpc.testnet.miden.io';
174174
const client = await WebClient.createClient(nodeEndpoint);
175175

176176
// 1. Sync with the latest blockchain state
@@ -243,9 +243,11 @@ export async function createMintConsume(): Promise<void> {
243243
return;
244244
}
245245

246-
const { WebClient, AccountStorageMode } = await import('@demox-labs/miden-sdk');
246+
const { WebClient, AccountStorageMode } = await import(
247+
'@demox-labs/miden-sdk'
248+
);
247249

248-
const nodeEndpoint = 'https://rpc.testnet.miden.io:443';
250+
const nodeEndpoint = 'https://rpc.testnet.miden.io';
249251
const client = await WebClient.createClient(nodeEndpoint);
250252

251253
// 1. Sync with the latest blockchain state
@@ -277,8 +279,8 @@ export async function createMintConsume(): Promise<void> {
277279

278280
```bash
279281
cd miden-web-app
280-
npm i
281-
npm run dev
282+
yarn install
283+
yarn dev
282284
```
283285

284286
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

Comments
 (0)