Skip to content

Commit b7bd9c3

Browse files
author
AztecBot
committed
Merge branch 'next' into merge-train/docs
2 parents cfa70ac + 69f7af6 commit b7bd9c3

22 files changed

Lines changed: 643 additions & 137 deletions

File tree

bootstrap.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ case "$cmd" in
637637
"ci-docs")
638638
export CI=1
639639
export USE_TEST_CACHE=1
640-
./bootstrap.sh
640+
BOOTSTRAP_TO=yarn-project ./bootstrap.sh
641641
docs/bootstrap.sh ci
642642
;;
643643
"ci-barretenberg-debug")

docs/CLAUDE.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ Default content
110110
- `static/img/` - Static images and assets
111111
- `static/aztec-nr-api/` - Auto-generated Aztec.nr API documentation (HTML)
112112
- `static/typescript-api/` - Auto-generated TypeScript API documentation (markdown)
113+
- `examples/` - Code examples (Noir circuits, Noir contracts, Solidity, TypeScript)
114+
- `examples/ts/` - TypeScript aztec.js examples with `docker-compose.yml` for CI execution
115+
- `examples/ts/aztecjs_runner/` - Runner script that executes examples against a live network
113116
- `scripts/` - Build and utility scripts
114117
- `scripts/typescript_api_generation/` - TypeScript API doc generation scripts and config
115118

@@ -142,6 +145,23 @@ Uses Docusaurus multi-instance versioning with separate version tracks:
142145
- Preprocessing macros (`#include_code`, `#release_version`, conditionals, etc.) only work in source folders, not in versioned copies
143146
- Create new versions with: `yarn docusaurus docs:version:<instance-id> <version>`
144147

148+
### Code Examples Pipeline
149+
150+
The `examples/` directory contains runnable code examples that are included in documentation via `#include_code` markers. The examples pipeline has two stages:
151+
152+
**Validation (type-checking)**: `examples/bootstrap.sh` compiles Noir circuits, Noir contracts, Solidity, and type-checks TypeScript examples. This runs on every PR.
153+
154+
**Execution (runtime testing)**: TypeScript examples in `examples/ts/` are executed against a live Aztec network via Docker Compose. The `examples/ts/docker-compose.yml` spins up Anvil (L1 fork), an Aztec local network, and a runner service that executes the examples.
155+
156+
- **CI**: `docs/bootstrap.sh ci` calls `examples/bootstrap.sh execute`, which uses `run_compose_test` from `ci3/`
157+
- **Local**: Start a sandbox manually, then run `examples/ts/aztecjs_runner/run.sh`
158+
- **`AZTEC_NODE_URL`**: All example `index.ts` files and `run.sh` use this env var (defaults to `http://localhost:8080`). In Docker Compose, it points to `http://local-network:8080`.
159+
160+
When adding new TypeScript examples:
161+
1. Create a directory under `examples/ts/` with `index.ts`, `config.yaml`, and empty `yarn.lock`
162+
2. Use `process.env.AZTEC_NODE_URL ?? "http://localhost:8080"` for the node URL
163+
3. Add the example to the list in `examples/ts/aztecjs_runner/run.sh` if it should be executed at runtime
164+
145165
## Documentation Review Standards
146166

147167
## Primary Review Objectives
@@ -329,5 +349,5 @@ Approved external documentation sources:
329349
- Suggest improvements even if they go beyond pure editing
330350
- When making changes to documentation processes or tooling, remember to check and update READMEs, project documentation (like this file), and code comments
331351

332-
Last updated: 2026-02-04
333-
Version: 1.4
352+
Last updated: 2026-02-23
353+
Version: 1.5

docs/developer_versioned_docs/version-v4.0.0-devnet.2-patch.1/docs/aztec-js/how_to_test.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,22 @@ This guide covers how to test Aztec smart contracts by connecting to a local net
1717

1818
Connect to your local Aztec network and create an embedded wallet:
1919

20-
```typescript title="setup" showLineNumbers
21-
const logger = createLogger("e2e:token");
20+
```typescript title="connect_to_network" showLineNumbers
21+
import { createAztecNodeClient, waitForNode } from "@aztec/aztec.js/node";
22+
import { EmbeddedWallet } from "@aztec/wallets/embedded";
23+
import { getInitialTestAccountsData } from "@aztec/accounts/testing";
2224

23-
// We create PXE client connected to the local network URL
24-
const node = createAztecNodeClient(AZTEC_NODE_URL);
25-
// Wait for local network to be ready
26-
await waitForNode(node, logger);
27-
const wallet = await TestWallet.create(node);
25+
const nodeUrl = process.env.AZTEC_NODE_URL ?? "http://localhost:8080";
26+
const node = createAztecNodeClient(nodeUrl);
2827

29-
const nodeInfo = await node.getNodeInfo();
28+
// Wait for the network to be ready
29+
await waitForNode(node);
3030

31-
logger.info(format("Aztec Local Network Info ", nodeInfo));
31+
// Create an EmbeddedWallet connected to the node
32+
const wallet = await EmbeddedWallet.create(node, { ephemeral: true });
3233
```
3334

34-
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v4.0.0-devnet.2-patch.1/yarn-project/end-to-end/src/composed/e2e_local_network_example.test.ts#L37-L50" target="_blank" rel="noopener noreferrer">Source code: yarn-project/end-to-end/src/composed/e2e_local_network_example.test.ts#L37-L50</a></sub></sup>
35+
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v4.0.0-devnet.2-patch.1/docs/examples/ts/aztecjs_connection/index.ts#L1-L14" target="_blank" rel="noopener noreferrer">Source code: docs/examples/ts/aztecjs_connection/index.ts#L1-L14</a></sub></sup>
3536
3637
The `EmbeddedWallet` manages accounts, tracks deployed contracts, and handles transaction proving. It connects to the Aztec node which provides access to both the Private eXecution Environment (PXE) and the network.
3738

docs/docs-developers/docs/aztec-js/how_to_read_data.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The `from` option specifies which address context to use for the simulation. Thi
2222

2323
### Basic simulation
2424

25-
#include_code simulate_function yarn-project/end-to-end/src/composed/docs_examples.test.ts typescript
25+
#include_code simulate_function docs/examples/ts/aztecjs_connection/index.ts typescript
2626

2727
### Handling return values
2828

docs/docs-developers/docs/aztec-js/how_to_test.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This guide covers how to test Aztec smart contracts by connecting to a local net
1717

1818
Connect to your local Aztec network and create an embedded wallet:
1919

20-
#include_code setup yarn-project/end-to-end/src/composed/e2e_local_network_example.test.ts typescript
20+
#include_code connect_to_network /docs/examples/ts/aztecjs_connection/index.ts typescript
2121

2222
The `EmbeddedWallet` manages accounts, tracks deployed contracts, and handles transaction proving. It connects to the Aztec node which provides access to both the Private eXecution Environment (PXE) and the network.
2323

@@ -53,7 +53,7 @@ const contract = await TokenContract.deploy(
5353

5454
Use `.simulate()` to read contract state without creating a transaction:
5555

56-
#include_code simulate_function yarn-project/end-to-end/src/composed/docs_examples.test.ts typescript
56+
#include_code simulate_function docs/examples/ts/aztecjs_connection/index.ts typescript
5757

5858
Simulations are free (no gas cost) and return the function's result directly. Use them for:
5959

docs/docs-developers/docs/foundational-topics/call_types.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Call Types
33
sidebar_position: 6
44
tags: [calls, contracts, execution]
55
description: Understand the different types of contract calls in Aztec, including private and public execution modes, and how they compare to Ethereum's call types.
6-
references: ["noir-projects/noir-contracts/contracts/app/auth_contract/src/main.nr", "noir-projects/noir-contracts/contracts/app/crowdfunding_contract/src/main.nr", "noir-projects/noir-contracts/contracts/app/lending_contract/src/main.nr", "noir-projects/noir-contracts/contracts/fees/fpc_contract/src/main.nr", "noir-projects/noir-contracts/contracts/protocol/router_contract/src/main.nr", "noir-projects/noir-contracts/contracts/protocol/router_contract/src/utils.nr", "yarn-project/end-to-end/src/composed/docs_examples.test.ts", "yarn-project/end-to-end/src/e2e_card_game.test.ts", "yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts"]
6+
references: ["noir-projects/noir-contracts/contracts/app/auth_contract/src/main.nr", "noir-projects/noir-contracts/contracts/app/crowdfunding_contract/src/main.nr", "noir-projects/noir-contracts/contracts/app/lending_contract/src/main.nr", "noir-projects/noir-contracts/contracts/fees/fpc_contract/src/main.nr", "noir-projects/noir-contracts/contracts/protocol/router_contract/src/main.nr", "noir-projects/noir-contracts/contracts/protocol/router_contract/src/utils.nr", "docs/examples/ts/aztecjs_connection/index.ts", "yarn-project/end-to-end/src/e2e_card_game.test.ts", "yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts"]
77
---
88

99
## What is a Call
@@ -197,7 +197,7 @@ There are two main ways to execute an Aztec contract function using the `aztec.j
197197

198198
This is used to get a result out of an execution, either private or public. It creates no transaction and spends no gas. The mental model is fairly close to that of [`eth_call`](#eth_call), in that it can be used to call any type of function, simulate its execution and get a result out of it. `simulate` is also the only way to run [utility functions](#utility).
199199

200-
#include_code simulate_function yarn-project/end-to-end/src/composed/docs_examples.test.ts typescript
200+
#include_code simulate_function docs/examples/ts/aztecjs_connection/index.ts typescript
201201

202202
:::warning
203203
No correctness is guaranteed on the result of `simulate`! Correct execution is entirely optional and left up to the client that handles this request.

docs/examples/bootstrap.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ function validate-ts {
7777
(cd ts && ./bootstrap.sh "$@")
7878
}
7979

80+
function execute-examples {
81+
echo_header "Executing TypeScript documentation examples"
82+
local COMPOSE_DIR="$REPO_ROOT/docs/examples/ts"
83+
run_compose_test "docs_examples" "docs-examples" "$COMPOSE_DIR"
84+
}
85+
8086
##############################################################################
8187
# CI failure handling - send Slack notifications instead of blocking the build
8288
##############################################################################
@@ -204,6 +210,7 @@ case "$cmd" in
204210
run_step "Compile (Noir contracts)" compile
205211
run_step "Compile (Solidity)" compile-solidity
206212
run_step "TypeScript validation" validate-ts
213+
run_step "Execute examples" execute-examples
207214

208215
if [[ ${#FAILED_STEPS[@]} -gt 0 ]]; then
209216
send_failure_slack_message
@@ -220,6 +227,9 @@ case "$cmd" in
220227
compile-solidity)
221228
compile-solidity
222229
;;
230+
execute)
231+
execute-examples
232+
;;
223233
*)
224234
default_cmd_handler "$@"
225235
;;

docs/examples/ts/README.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# TypeScript Documentation Examples
2+
3+
This directory contains TypeScript examples used in the Aztec documentation. Each example is a self-contained project that demonstrates specific Aztec.js functionality.
4+
5+
## Directory Structure
6+
7+
Each example directory contains:
8+
- `index.ts` - The example code with `docs:start:` and `docs:end:` markers for inclusion in documentation
9+
- `config.yaml` - Specifies dependencies and any custom contract artifacts needed
10+
- `yarn.lock` - Empty file to prevent yarn from using parent monorepo's yarn.lock
11+
12+
## Validation: Type Checking
13+
14+
The `bootstrap.sh` script validates all examples by:
15+
16+
1. Reading `config.yaml` to determine dependencies and custom contracts
17+
2. Running codegen for any custom contracts specified (from `docs/target/`)
18+
3. Installing linked `@aztec/*` dependencies from `yarn-project/`
19+
4. Running `tsc --noEmit` to type-check the example
20+
21+
Run validation for all examples:
22+
```bash
23+
./bootstrap.sh
24+
```
25+
26+
Run validation for specific example(s):
27+
```bash
28+
./bootstrap.sh aztecjs_connection aztecjs_advanced
29+
```
30+
31+
## Execution: Test Runner
32+
33+
The `aztecjs_runner/run.sh` script executes examples against a live local Aztec network to verify they work correctly.
34+
35+
### CI Execution (Docker Compose)
36+
37+
In CI, examples run via `docker-compose.yml` which spins up an Anvil fork, a local Aztec network, and runs the examples automatically. This is triggered by `docs/examples/bootstrap.sh execute` (called from `docs/bootstrap.sh ci`).
38+
39+
```bash
40+
# Run via bootstrap (recommended for CI)
41+
cd docs/examples && ./bootstrap.sh execute
42+
43+
# Or invoke docker-compose directly
44+
cd docs/examples/ts && run_compose_test docs_examples docs-examples .
45+
```
46+
47+
### Local Execution
48+
49+
For local development, start the sandbox manually and run examples directly.
50+
51+
#### Prerequisites
52+
53+
- Local Aztec network running (default: `localhost:8080`)
54+
- Built yarn-project packages
55+
56+
#### Usage
57+
58+
Run all examples:
59+
```bash
60+
cd aztecjs_runner
61+
./run.sh
62+
```
63+
64+
Run specific example(s):
65+
```bash
66+
./run.sh connection # aztecjs_connection
67+
./run.sh getting_started # aztecjs_getting_started
68+
./run.sh advanced authwit # multiple examples
69+
```
70+
71+
#### Environment Variables
72+
73+
| Variable | Description | Default |
74+
|----------|-------------|---------|
75+
| `AZTEC_NODE_URL` | URL of the Aztec node to connect to | `http://localhost:8080` |
76+
77+
The `AZTEC_NODE_URL` env var is used by both the runner script and the example `index.ts` files. In Docker Compose, it is set to `http://local-network:8080` to point at the compose network's Aztec node.
78+
79+
### Currently Tested Examples
80+
81+
| Example | Description |
82+
|---------|-------------|
83+
| `aztecjs_connection` | Basic network connection, account setup, token deployment |
84+
| `aztecjs_getting_started` | Complete getting started tutorial flow |
85+
| `aztecjs_advanced` | NO_WAIT transactions, BatchCall, sponsored FPC, events |
86+
| `aztecjs_authwit` | Authentication witnesses for delegated actions |
87+
| `aztecjs_testing` | Test patterns: minting, transfers, revert testing |
88+
89+
### Examples Not Executed (Type-Checked Only)
90+
91+
These examples require additional infrastructure or custom contracts with verification keys:
92+
93+
| Example | Reason |
94+
|---------|--------|
95+
| `bob_token_contract` | Custom contract requires verification keys |
96+
| `token_bridge` | Requires L1 contracts and bridge infrastructure |
97+
| `recursive_verification` | Requires prover and verification key generation |
98+
99+
## Adding New Examples
100+
101+
1. Create a new directory with your example name
102+
2. Add `index.ts` with your example code
103+
3. Add `config.yaml` specifying dependencies:
104+
105+
```yaml
106+
# For examples using pre-built contracts from @aztec/noir-contracts.js
107+
contracts: []
108+
109+
dependencies:
110+
- "@aztec/aztec.js"
111+
- "@aztec/accounts"
112+
- "@aztec/test-wallet"
113+
- "@aztec/noir-contracts.js"
114+
```
115+
116+
4. Create empty `yarn.lock` file
117+
5. Run `./bootstrap.sh your_example_name` to validate
118+
6. If the example can run against a live network, add it to `aztecjs_runner/run.sh`
119+
120+
## File Management
121+
122+
The validation and runner scripts generate temporary files during execution. These are cleaned up automatically, but if you need to manually clean:
123+
124+
```bash
125+
# In each example directory
126+
rm -rf node_modules .yarn artifacts package.json tsconfig.json .yarnrc.yml
127+
rm -f .editorconfig .gitattributes .gitignore README.md codegenCache.json
128+
> yarn.lock # Keep empty
129+
```

docs/examples/ts/aztecjs_advanced/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import { getPublicEvents } from "@aztec/aztec.js/events";
1616
import { BlockNumber } from "@aztec/aztec.js/fields";
1717

1818
// Setup: connect to network
19-
const node = createAztecNodeClient("http://localhost:8080");
19+
const node = createAztecNodeClient(process.env.AZTEC_NODE_URL ?? "http://localhost:8080");
2020
await waitForNode(node);
21-
const wallet = await EmbeddedWallet.create(node);
21+
const wallet = await EmbeddedWallet.create(node, { ephemeral: true });
2222

2323
const testAccounts = await getInitialTestAccountsData();
2424
const [aliceAddress, bobAddress] = await Promise.all(
@@ -126,6 +126,10 @@ await token.methods
126126
.mint_to_public(aliceAddress, 10000n)
127127
.send({ from: aliceAddress });
128128

129+
await token.methods
130+
.mint_to_private(aliceAddress, 10000n)
131+
.send({ from: aliceAddress });
132+
129133
// docs:start:no_wait_deploy
130134
// Use NO_WAIT to get the transaction hash immediately and track deployment
131135
const txHash = await TokenContract.deploy(

docs/examples/ts/aztecjs_authwit/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import { Fr } from "@aztec/aztec.js/fields";
66
import { SetPublicAuthwitContractInteraction } from "@aztec/aztec.js/authorization";
77

88
// Setup: connect to network and deploy a token contract
9-
const node = createAztecNodeClient("http://localhost:8080");
9+
const node = createAztecNodeClient(
10+
process.env.AZTEC_NODE_URL ?? "http://localhost:8080",
11+
);
1012
await waitForNode(node);
11-
const wallet = await EmbeddedWallet.create(node);
13+
const wallet = await EmbeddedWallet.create(node, { ephemeral: true });
1214

1315
const testAccounts = await getInitialTestAccountsData();
1416
const [aliceAddress, bobAddress] = await Promise.all(
@@ -59,7 +61,13 @@ const privateWitness = await wallet.createAuthWit(aliceAddress, {
5961
});
6062

6163
// Bob executes the transfer, providing the authwit
62-
await privateAction.send({ from: bobAddress, authWitnesses: [privateWitness] });
64+
// additionalScopes lets the PXE access Alice's private state
65+
// during authwit verification
66+
await privateAction.send({
67+
from: bobAddress,
68+
authWitnesses: [privateWitness],
69+
additionalScopes: [aliceAddress],
70+
});
6371
// docs:end:private_authwit
6472

6573
// docs:start:public_authwit

0 commit comments

Comments
 (0)