Skip to content

Commit b0c1885

Browse files
critesjoshclaude
andcommitted
Fix generate_data.ts for Aztec v3 API
- Use TestWallet instead of createPXEClient (removed in v3) - Use getInitialTestAccountsData and wallet.createSchnorrAccount - Update imports to use v3 subpaths - Fix storage slot reference to use user_balances Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 6e5e922 commit b0c1885

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

note-send-proof/scripts/generate_data.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
11
import { GettingStartedContract } from '../contract/artifacts/GettingStarted.js';
2-
import {
3-
createPXEClient,
4-
waitForPXE,
5-
createAztecNodeClient,
6-
Fr,
7-
} from '@aztec/aztec.js';
8-
import { getInitialTestAccountsWallets } from '@aztec/accounts/testing';
2+
import { Fr } from '@aztec/aztec.js/fields';
3+
import { createAztecNodeClient, waitForNode } from '@aztec/aztec.js/node';
4+
import { getInitialTestAccountsData } from '@aztec/accounts/testing';
5+
import { TestWallet } from '@aztec/test-wallet/server';
96
import { computeNoteHashNonce, computeUniqueNoteHash, deriveStorageSlotInMap, siloNoteHash } from '@aztec/stdlib/hash';
10-
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
7+
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
118
import fs from 'fs';
129
import { exit } from 'process';
1310

1411
const NOTE_HASH_SEPARATOR = 1;
15-
const SANDBOX_URL = 'http://localhost:8080';
12+
const NODE_URL = 'http://localhost:8080';
1613

1714
async function main() {
18-
console.log(`Connecting to PXE at ${SANDBOX_URL}`);
19-
const pxe = createPXEClient(SANDBOX_URL);
20-
await waitForPXE(pxe);
21-
console.log('PXE client connected');
22-
23-
const wallets = await getInitialTestAccountsWallets(pxe);
24-
const deployerWallet = wallets[0];
25-
const deployerAddress = deployerWallet.getAddress();
15+
console.log(`Connecting to Aztec node at ${NODE_URL}`);
16+
const aztecNode = createAztecNodeClient(NODE_URL);
17+
await waitForNode(aztecNode);
18+
console.log('Aztec node connected');
19+
20+
const wallet = await TestWallet.create(aztecNode, { dataDirectory: 'pxe-data-gen' });
21+
console.log('TestWallet created');
22+
23+
const accountsData = await getInitialTestAccountsData();
24+
const deployerAccount = await wallet.createSchnorrAccount(
25+
accountsData[0].secret,
26+
accountsData[0].salt,
27+
accountsData[0].signingKey
28+
);
29+
const deployerAddress = deployerAccount.address;
2630

2731
console.log('Deploying GettingStarted contract...');
28-
const gettingStarted = await GettingStartedContract.deploy(deployerWallet).send({
32+
const gettingStarted = await GettingStartedContract.deploy(wallet, deployerAddress).send({
2933
from: deployerAddress,
3034
}).wait();
3135

@@ -34,24 +38,20 @@ async function main() {
3438
const NOTE_VALUE = 69;
3539

3640
console.log('Creating note for user...');
37-
const tx = gettingStarted.contract.methods.create_note_for_user(NOTE_VALUE);
38-
39-
const txExecutionRequest = await tx.create();
40-
const txRequestHash = await txExecutionRequest.toTxRequest().hash();
41-
42-
console.log('TX REQUEST HASH', txRequestHash.toString());
43-
44-
const sentTx = await tx.send({ from: deployerAddress }).wait();
41+
const sentTx = await gettingStarted.contract.methods
42+
.create_note_for_user(NOTE_VALUE)
43+
.send({ from: deployerAddress })
44+
.wait();
4545
console.log('TX HASH', sentTx.txHash.toString());
4646

47-
const node = createAztecNodeClient(SANDBOX_URL);
47+
const node = createAztecNodeClient(NODE_URL);
4848
const txEffect = await node.getTxEffect(sentTx.txHash);
4949

5050
if (txEffect === undefined) {
5151
throw new Error('Cannot find txEffect from tx hash');
5252
}
5353

54-
const storageSlot = await deriveStorageSlotInMap(GettingStartedContract.storage.user_private_state.slot, deployerAddress);
54+
const storageSlot = await deriveStorageSlotInMap(GettingStartedContract.storage.user_balances.slot, deployerAddress);
5555

5656
const NOTE_RANDOMNESS = new Fr(6969);
5757

@@ -61,7 +61,7 @@ async function main() {
6161

6262
const INDEX_OF_NOTE_HASH_IN_TRANSACTION = 0;
6363

64-
const nonceGenerator = txEffect?.data.nullifiers[0] ?? txRequestHash;
64+
const nonceGenerator = txEffect.data.nullifiers[0];
6565

6666
const noteHashNonce = await computeNoteHashNonce(nonceGenerator, INDEX_OF_NOTE_HASH_IN_TRANSACTION);
6767

0 commit comments

Comments
 (0)