Skip to content

Commit 9d87cd3

Browse files
committed
fix(docs): enhance tutorials with Noir Language Server tips and update versioning sections
## Summary This PR updates the developer documentation tutorials to use the latest Aztec syntax and improves overall tutorial quality: ### Tutorial Updates **Counter Contract Tutorial** - Migrated dependencies from `aztec-packages` monorepo to the standalone `aztec-nr` repository - Replaced deprecated `easy_private_state`/`EasyPrivateUint` with `balance_set`/`BalanceSet` - Updated import explanations for new patterns (`MessageDelivery`, `debug_log_format`, `Owned`) - Fixed function descriptions to reflect constrained message delivery patterns **Token Contract Tutorial** - Added explicit `mkdir` and `cd` commands for clearer project setup - Migrated dependencies to `aztec-nr` repository - Updated to use `BalanceSet` instead of `EasyPrivateUint` - Added instruction to start local network before deployment **Aztec.js Getting Started Tutorial** - Refactored to use `#include_code` macros instead of inline code blocks - Added `@aztec/test-wallet` dependency - Created companion example at `docs/examples/ts/aztecjs_getting_started/` - Improved step-by-step flow with numbered instructions **Token Bridge Tutorial** - Added tip about Noir Language Server VS Code extension - Updated dependency references to `aztec-nr` repository - Fixed `#[private]` to `#[external("private")]` annotation - Corrected command syntax from `aztec new --contract` to `aztec new` - Updated terminology from "constrained event" to "constrained message delivery" **Local Network Tutorial** - Updated table of contents with detailed navigation - Fixed `aztec-up` command to include version placeholder ### Example Code Updates - Created new `aztecjs_getting_started/` example with full working code - Fixed `bob_token_contract/index.ts`: added missing `await` and removed unused variable - Updated `bootstrap.sh` to handle examples using only pre-built packages (no custom contracts) - Updated NFT bridge contracts with modern Aztec syntax (`self.call()`, `Owned` wrapper, proper imports) - Fixed relative paths in example `Nargo.toml` files - Applied `noir fmt` formatting to contract examples ## Test plan - [ ] Verify tutorials build correctly with `yarn build` - [ ] Confirm example TypeScript projects pass validation with `bootstrap.sh` - [ ] Test that code snippets in tutorials match the example source files 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 8bd0839 commit 9d87cd3

File tree

18 files changed

+294
-185
lines changed

18 files changed

+294
-185
lines changed

docs/Nargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[workspace]
22
members = [
33
"examples/contracts/counter_contract",
4-
"examples/contracts/bob_token_contract"
4+
"examples/contracts/bob_token_contract",
5+
"examples/tutorials/token_bridge_contract/contracts/aztec/nft",
6+
"examples/tutorials/token_bridge_contract/contracts/aztec/nft_bridge"
57
]

docs/docs-developers/docs/tutorials/contract_tutorials/counter_contract.md

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ Add the following dependencies to `Nargo.toml` under the autogenerated content:
4040

4141
```toml
4242
[dependencies]
43-
aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="noir-projects/aztec-nr/aztec" }
44-
value_note = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="noir-projects/aztec-nr/value-note"}
45-
easy_private_state = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="noir-projects/aztec-nr/easy-private-state"}
43+
aztec = { git="https://github.com/AztecProtocol/aztec-nr/", tag="#include_aztec_version", directory="aztec" }
44+
balance_set = { git="https://github.com/AztecProtocol/aztec-nr/", tag="#include_aztec_version", directory="balance-set" }
4645
```
4746

4847
## Define the functions
@@ -70,21 +69,27 @@ pub contract Counter {
7069

7170
#include_code imports /docs/examples/contracts/counter_contract/src/main.nr rust
7271

73-
- `use aztec::macros::{functions::{external, initializer}, storage::storage},`
72+
- `macros::{functions::{external, initializer}, storage::storage}`
7473
Imports the macros needed to define function types (`external`, `initializer`) and the `storage` macro for declaring contract storage structures.
7574

76-
- `protocol_types::{address::AztecAddress, traits::ToField},`
77-
Brings in `AztecAddress` (used to identify accounts/contracts) and traits for converting values to and from field elements, necessary for serialization and formatting inside Aztec.
75+
- `messages::message_delivery::MessageDelivery`
76+
Imports `MessageDelivery` for specifying how note delivery should be handled (e.g., constrained onchain delivery).
7877

79-
- `state_vars::Map,`
80-
Brings in `Map`, used for creating state mappings, like our counters.
78+
- `oracle::debug_log::debug_log_format`
79+
Imports a debug logging utility for printing formatted messages during contract execution.
8180

82-
- `use easy_private_state::EasyPrivateUint;`
83-
Imports a wrapper to manage private integer-like state variables (ie our counter), abstracting away notes.
81+
- `protocol_types::{address::AztecAddress, traits::ToField}`
82+
Brings in `AztecAddress` (used to identify accounts/contracts) and traits for converting values to field elements, necessary for serialization and formatting inside Aztec.
83+
84+
- `state_vars::Owned`
85+
Brings in `Owned`, a wrapper for state variables that have a single owner.
86+
87+
- `use balance_set::BalanceSet`
88+
Imports `BalanceSet` from the `balance_set` dependency, which provides functionality for managing private balances (used for our counter).
8489

8590
## Declare storage
8691

87-
Add this below the imports. It declares the storage variables for our contract. We are going to store a mapping of values for each `AztecAddress`.
92+
Add this below the imports. It declares the storage variables for our contract. We use an `Owned` state variable wrapping a `BalanceSet` to manage private balances for each owner.
8893

8994
#include_code storage_struct /docs/examples/contracts/counter_contract/src/main.nr rust
9095

@@ -96,41 +101,41 @@ Let’s create a constructor method to run on deployment that assigns an initial
96101

97102
#include_code constructor /docs/examples/contracts/counter_contract/src/main.nr rust
98103

99-
This function accesses the counts from storage. Then it assigns the passed initial counter to the `owner`'s counter privately using `at().add()`.
104+
This function accesses the counters from storage. It adds the `headstart` value to the `owner`'s counter using `at().add()`, then calls `.deliver(MessageDelivery.CONSTRAINED_ONCHAIN)` to ensure the note is delivered onchain.
100105

101106
We have annotated this and other functions with `#[external("private")]` which are ABI macros so the compiler understands it will handle private inputs.
102107

103108
## Incrementing our counter
104109

105-
Now lets implement the `increment` function we defined in the first step.
110+
Now let's implement an `increment` function to increase the counter.
106111

107112
#include_code increment /docs/examples/contracts/counter_contract/src/main.nr rust
108113

109-
The `increment` function works very similarly to the `constructor`, but instead directly adds 1 to the counter rather than passing in an initial count parameter.
114+
The `increment` function works similarly to the `initialize` function. It logs a debug message, then adds 1 to the owner's counter and delivers the note onchain.
110115

111116
## Getting a counter
112117

113-
The last thing we need to implement is the function in order to retrieve a counter. In the `getCounter` we defined in the first step, write this:
118+
The last thing we need to implement is a function to retrieve a counter value.
114119

115120
#include_code get_counter /docs/examples/contracts/counter_contract/src/main.nr rust
116121

117-
This is a `utility` function which is used to obtain the counter information outside of a transaction. We retrieve a reference to the `owner`'s `counter` from the `counters` Map. The `get_balance` function then operates on the owner's counter. This yields a private counter that only the private key owner can decrypt.
122+
This is a `utility` function used to obtain the counter value outside of a transaction. We access the `owner`'s balance from the `counters` storage variable using `at(owner)`, then call `balance_of()` to retrieve the current count. This yields a private counter that only the owner can decrypt.
118123

119124
## Compile
120125

121126
Now we've written a simple Aztec.nr smart contract, we can compile it.
122127

123128
### Compile the smart contract
124129

125-
In `./counter/` directory, run these commands:
130+
In the `./counter/` directory, run:
126131

127132
```bash
128-
aztec compile # compiles the contract
133+
aztec compile
129134
```
130135

131-
The first command compiles your Noir contract and creates a `target` folder with a `.json` artifact inside. The second command processes these artifacts for use with Aztec (transpiling for the AVM and generating verification keys). Do not worry if you see some warnings - Aztec is in fast development and it is likely you will see some irrelevant warning messages.
136+
This command compiles your Noir contract and creates a `target` folder with a `.json` artifact inside.
132137

133-
After compiling and processing, you can generate a typescript class using `aztec codegen` command.
138+
After compiling, you can generate a TypeScript class using the `aztec codegen` command.
134139

135140
In the same directory, run this:
136141

docs/docs-developers/docs/tutorials/contract_tutorials/token_contract.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ We'll create BOB tokens with:
3838
Let's create a simple yarn + aztec.nr project:
3939

4040
```bash
41+
mkdir bob_token_contract
42+
cd bob_token_contract
4143
yarn init
4244
# This is to ensure yarn uses node_modules instead of pnp for dependency installation
4345
yarn config set nodeLinker node-modules
@@ -55,7 +57,7 @@ We have a messy, but working structure. In `src/main.nr` we even have a proto-co
5557
}
5658
```
5759

58-
The `#[aztec]` macro transforms our contract code to work with Aztec's privacy protocol. We'll rename it from `StarterToken` to `BobToken` to reflect our use case.
60+
The `#[aztec]` macro transforms our contract code to work with Aztec's privacy protocol.
5961

6062
Let's import the Aztec.nr library by adding it to our dependencies in `Nargo.toml`:
6163

@@ -65,7 +67,7 @@ name = "bob_token_contract"
6567
type = "contract"
6668

6769
[dependencies]
68-
aztec = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "#include_aztec_version", directory = "noir-projects/aztec-nr/aztec" }
70+
aztec = { git = "https://github.com/AztecProtocol/aztec-nr/", tag = "#include_aztec_version", directory = "aztec" }
6971
```
7072

7173
Since we're here, let's import more specific stuff from this library:
@@ -184,7 +186,11 @@ You should now have a nice typescript interface in a new `artifacts` folder. Pre
184186

185187
### Deploy and Test
186188

187-
Create `index.ts`. We will connect to our running local network and its wallet, then deploy the test accounts and get three wallets out of it.
189+
Create `index.ts`. We will connect to our running local network and its wallet, then deploy the test accounts and get three wallets out of it. Ensure that your local network is running:
190+
191+
```bash
192+
aztec start --local-network
193+
```
188194

189195
Then we will use the `giggleWallet` to deploy our contract, mint 100 BOB to Alice, then transfer 10 of those to Bob's Clinic publicly... for now. Let's go:
190196

@@ -251,18 +257,19 @@ For something like balances, you can use a simple library called `easy_private_s
251257

252258
```toml
253259
[dependencies]
254-
easy_private_state = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "#include_aztec_version", directory = "noir-projects/aztec-nr/easy-private-state" }
260+
aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag="#include_aztec_version", directory="aztec" }
261+
balance_set = { git = "https://github.com/AztecProtocol/aztec-nr/", tag = "#include_aztec_version", directory = "balance-set" }
255262
```
256263

257-
Then import `EasyPrivateUint` in our contract:
264+
Then import `BalanceSet` in our contract:
258265

259266
```rust
260267
use aztec::macros::aztec;
261268

262269
#[aztec]
263270
pub contract BobToken {
264271
// ... other imports
265-
use easy_private_state::EasyPrivateUint;
272+
use balance_set::BalanceSet;
266273
// ...
267274
}
268275
```
@@ -271,7 +278,7 @@ We need to update the contract storage to have private balances as well:
271278

272279
#include_code storage /docs/examples/contracts/bob_token_contract/src/main.nr rust
273280

274-
The `private_balances` use `EasyPrivateUint` which manages encrypted notes automatically.
281+
The `private_balances` use `BalanceSet` which manages encrypted notes automatically.
275282

276283
### Moving Tokens to Privateland
277284

docs/docs-developers/docs/tutorials/js_tutorials/aztecjs-getting-started.md

Lines changed: 45 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ Before starting, make sure to be running Aztec local network at version #include
1212

1313
## Set up the project
1414

15-
Let's initialize a yarn project first. You can init it with the dependencies we need:
15+
First, create a new directory for your project and initialize it with yarn:
16+
17+
```sh
18+
mkdir token-tutorial
19+
cd token-tutorial
20+
yarn init -y
21+
```
22+
23+
Next, add the TypeScript dependencies:
1624

1725
```sh
1826
yarn add typescript @types/node tsx
@@ -27,7 +35,7 @@ Never heard of `tsx`? Well, it will just run `typescript` with reasonable defaul
2735
Let's also import the Aztec dependencies for this tutorial:
2836

2937
```sh
30-
yarn add @aztec/aztec.js@#include_version_without_prefix @aztec/accounts@#include_version_without_prefix @aztec/noir-contracts.js@#include_version_without_prefix
38+
yarn add @aztec/aztec.js@#include_version_without_prefix @aztec/accounts@#include_version_without_prefix @aztec/noir-contracts.js@#include_version_without_prefix @aztec/test-wallet@#include_version_without_prefix
3139
```
3240

3341
Aztec.js assumes your project is using ESM, so make sure you add `"type": "module"` to `package.json`. You probably also want at least a `start` script. For example:
@@ -43,105 +51,69 @@ Aztec.js assumes your project is using ESM, so make sure you add `"type": "modul
4351

4452
### Connecting to the local network
4553

46-
We want to [connect to our running local network](../../aztec-js/how_to_connect_to_local_network.md) and import the test accounts into a new wallet. Let's call them Alice and Bob (of course). Create an `index.ts` with it:
54+
Now let's connect to the Aztec local network and set up test accounts.
4755

48-
```typescript
49-
import { createAztecNodeClient } from "@aztec/aztec.js/node";
50-
import { TestWallet } from "@aztec/test-wallet/server";
51-
import { getInitialTestAccountsData } from "@aztec/accounts/testing";
56+
**Step 1: Start the Aztec Local Network**
5257

53-
const nodeUrl = "http://localhost:8080";
54-
const node = createAztecNodeClient(nodeUrl);
55-
const wallet = await TestWallet.create(node);
58+
In a separate terminal, run:
5659

57-
const [alice, bob] = await getInitialTestAccountsData();
58-
await wallet.createSchnorrAccount(alice.secret, alice.salt);
59-
await wallet.createSchnorrAccount(bob.secret, bob.salt);
60+
```sh
61+
aztec start --local-network
6062
```
6163

62-
## Deploy the token contract
64+
Keep this terminal running throughout the tutorial.
6365

64-
Now that we have our accounts loaded, let's move on to deploy our pre-compiled token smart contract. You can find the full code for the contract [here (GitHub link)](https://github.com/AztecProtocol/aztec-packages/tree/master/noir-projects/noir-contracts/contracts/app/token_contract/src).
66+
**Step 2: Create the index.ts file**
6567

66-
Let's import the interface directly, and make Alice the admin:
68+
Create an `index.ts` file in the root of your project with the following code. This connects to the local network and imports test accounts (Alice and Bob):
6769

68-
```typescript
69-
import { TokenContract } from "@aztec/noir-contracts.js/Token";
70+
#include_code setup /docs/examples/ts/aztecjs_getting_started/index.ts typescript
7071

71-
const token = await TokenContract.deploy(
72-
wallet,
73-
alice.address,
74-
"TokenName",
75-
"TKN",
76-
18
77-
)
78-
.send({ from: alice.address })
79-
.deployed();
72+
**Step 3: Verify the script runs**
73+
74+
Run the script to make sure everything is set up correctly:
75+
76+
```sh
77+
yarn start
8078
```
8179

80+
If there are no errors, you're ready to continue. For more details on connecting to the local network, see [this guide](../../aztec-js/how_to_connect_to_local_network.md).
81+
82+
## Deploy the token contract
83+
84+
Now that we have our accounts loaded, let's deploy a pre-compiled token contract from the Aztec library. You can find the full code for the contract [here (GitHub link)](https://github.com/AztecProtocol/aztec-packages/tree/#include_aztec_version/noir-projects/noir-contracts/contracts/app/token_contract/src).
85+
86+
Add the following to `index.ts` to import the contract and deploy it with Alice as the admin:
87+
88+
#include_code deploy /docs/examples/ts/aztecjs_getting_started/index.ts typescript
89+
8290
## Mint and transfer
8391

8492
Let's go ahead and have Alice mint herself some tokens, in private:
8593

86-
```typescript
87-
await token.methods
88-
.mint_to_private(alice.address, 100)
89-
.send({ from: alice.address })
90-
.wait();
91-
```
94+
#include_code mint /docs/examples/ts/aztecjs_getting_started/index.ts typescript
9295

9396
Let's check both Alice's and Bob's balances now:
9497

95-
```typescript
96-
let aliceBalance = await token.methods
97-
.balance_of_private(alice.address)
98-
.simulate({ from: alice.address });
99-
console.log(`Alice's balance: ${aliceBalance}`); // whoooaa 100 tokens
100-
let bobBalance = await token.methods
101-
.balance_of_private(bob.address)
102-
.simulate({ from: bob.address });
103-
console.log(`Bob's balance: ${bobBalance}`); // you get nothin' 🥹
104-
```
98+
#include_code check_balances /docs/examples/ts/aztecjs_getting_started/index.ts typescript
99+
100+
Alice should have 100 tokens, while Bob has none yet.
105101

106102
Great! Let's have Alice transfer some tokens to Bob, also in private:
107103

108-
```typescript
109-
await token.methods
110-
.transfer(bob.address, 10)
111-
.send({ from: alice.address })
112-
.wait();
113-
bobBalance = await token.methods
114-
.balance_of_private(bob.address)
115-
.simulate({ from: bob.address });
116-
console.log(`Bob's balance: ${bobBalance}`);
117-
```
104+
#include_code transfer /docs/examples/ts/aztecjs_getting_started/index.ts typescript
118105

119-
Nice, Bob should now see 10 tokens in his balance! Thanks Alice!
106+
Bob should now see 10 tokens in his balance.
120107

121108
## Other cool things
122109

123110
Say that Alice is nice and wants to set Bob as a minter. Even though it's a public function, it can be called in a similar way:
124111

125-
```typescript
126-
await token.methods
127-
.set_minter(bob.address, true)
128-
.send({ from: alice.address })
129-
.wait();
130-
```
112+
#include_code set_minter /docs/examples/ts/aztecjs_getting_started/index.ts typescript
131113

132-
Bob is now the minter, so he can mint some tokens to himself, notice that for the time being, you need to bind `token` to Bob's wallet with `withWallet(bob)`:
133-
134-
```typescript
135-
await token
136-
.withWallet(bob)
137-
.methods.mint_to_private(bob.address, 100)
138-
.send({ from: bob.address })
139-
.wait();
140-
bobBalance = await token.methods
141-
.balance_of_private(bob.address)
142-
.simulate({ from: bob.address });
143-
console.log(`Bob's balance: ${bobBalance}`);
144-
```
114+
Bob is now the minter, so he can mint some tokens to himself:
115+
116+
#include_code bob_mints /docs/examples/ts/aztecjs_getting_started/index.ts typescript
145117

146118
:::info
147119

0 commit comments

Comments
 (0)