Skip to content

Commit 0ea54b4

Browse files
committed
Refactor account deployment scripts to utilize setupWallet utility and remove PXE dependency. Update deployment logic in multiple scripts for consistency and improved clarity.
1 parent 827ebcb commit 0ea54b4

File tree

8 files changed

+90
-92
lines changed

8 files changed

+90
-92
lines changed

scripts/deploy_account.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { createLogger, Logger } from "@aztec/aztec.js";
2-
import { setupPXE } from "../src/utils/setup_wallet.js";
1+
import { Logger, createLogger } from "@aztec/aztec.js/log";
32
import { deploySchnorrAccount } from "../src/utils/deploy_account.js";
43

54
export async function deployAccount() {
65
let logger: Logger;
76
logger = createLogger('aztec:aztec-starter');
8-
const pxe = await setupPXE();
9-
await deploySchnorrAccount(pxe);
7+
await deploySchnorrAccount();
108
}
119

1210
deployAccount();

scripts/deploy_contract.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,49 @@
11
import { PrivateVotingContract } from "../src/artifacts/PrivateVoting.js"
2-
import { createLogger, PXE, Logger, SponsoredFeePaymentMethod, Fr } from "@aztec/aztec.js";
2+
import { Logger, createLogger } from "@aztec/aztec.js/log";
3+
import { SponsoredFeePaymentMethod } from "@aztec/aztec.js/fee/testing";
4+
import { Fr } from "@aztec/aztec.js/fields";
35
import { TokenContract } from "@aztec/noir-contracts.js/Token"
4-
import { setupPXE } from "../src/utils/setup_wallet.js";
6+
import { setupWallet } from "../src/utils/setup_wallet.js";
57
import { getSponsoredFPCInstance } from "../src/utils/sponsored_fpc.js";
68
import { SponsoredFPCContract } from "@aztec/noir-contracts.js/SponsoredFPC";
79
import { deploySchnorrAccount } from "../src/utils/deploy_account.js";
810
import { getTimeouts } from "../config/config.js";
911

1012
async function main() {
11-
let pxe: PXE;
1213
let logger: Logger;
1314

1415
logger = createLogger('aztec:aztec-starter');
1516
logger.info(`🚀 Starting contract deployment process...`);
1617

1718
const timeouts = getTimeouts();
1819

19-
// Setup PXE
20-
logger.info('📡 Setting up PXE connection...');
21-
pxe = await setupPXE();
22-
const nodeInfo = await pxe.getNodeInfo();
23-
logger.info(`📊 Connected to node`);
20+
// Setup wallet
21+
logger.info('📡 Setting up wallet...');
22+
const wallet = await setupWallet();
23+
logger.info(`📊 Wallet set up successfully`);
2424

2525
// Setup sponsored FPC
2626
logger.info('💰 Setting up sponsored fee payment contract...');
2727
const sponsoredFPC = await getSponsoredFPCInstance();
2828
logger.info(`💰 Sponsored FPC instance obtained at: ${sponsoredFPC.address}`);
2929

30-
logger.info('📝 Registering sponsored FPC contract with PXE...');
31-
await pxe.registerContract({ instance: sponsoredFPC, artifact: SponsoredFPCContract.artifact });
30+
logger.info('📝 Registering sponsored FPC contract with wallet...');
31+
await wallet.registerContract({ instance: sponsoredFPC, artifact: SponsoredFPCContract.artifact });
3232
const sponsoredPaymentMethod = new SponsoredFeePaymentMethod(sponsoredFPC.address);
3333
logger.info('✅ Sponsored fee payment method configured');
3434

3535
// Deploy account
3636
logger.info('👤 Deploying Schnorr account...');
37-
let accountManager = await deploySchnorrAccount(pxe);
38-
const wallet = await accountManager.getWallet();
39-
const address = await accountManager.getAddress();
37+
let accountManager = await deploySchnorrAccount(wallet);
38+
const address = accountManager.address;
4039
logger.info(`✅ Account deployed successfully at: ${address}`);
4140

4241
// Deploy voting contract
4342
logger.info('🗳️ Starting voting contract deployment...');
4443
logger.info(`📋 Admin address for voting contract: ${address}`);
4544

4645
const deployTx = PrivateVotingContract.deploy(wallet, address).send({
47-
from: wallet.getAddress(),
46+
from: address,
4847
fee: { paymentMethod: sponsoredPaymentMethod }
4948
});
5049

@@ -61,7 +60,7 @@ async function main() {
6160
// Test a read operation
6261
logger.info('🧪 Testing contract read operation...');
6362
const initialVoteCount = await votingContract.methods.get_vote(Fr.fromString("1")).simulate({
64-
from: wallet.getAddress()
63+
from: address
6564
});
6665
logger.info(`📊 Initial vote count for candidate 1: ${initialVoteCount}`);
6766

scripts/get_block.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { PXE } from "@aztec/aztec.js";
2-
import { setupPXE } from "../src/utils/setup_wallet.js";
1+
import { createAztecNodeClient } from "@aztec/aztec.js/node";
2+
import { getAztecNodeUrl } from "../config/config.js";
33

44
async function main() {
55

6-
let pxe: PXE;
7-
pxe = await setupPXE();
8-
9-
let block = await pxe.getBlock(1);
6+
const nodeUrl = getAztecNodeUrl();
7+
const node = createAztecNodeClient(nodeUrl);
8+
let block = await node.getBlock(1);
109
console.log(block)
1110
console.log(await block?.hash())
1211
}

scripts/interaction_existing_contract.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import { createLogger, Logger, SponsoredFeePaymentMethod, Fr, AztecAddress } from "@aztec/aztec.js";
1+
import { Logger, createLogger } from "@aztec/aztec.js/log";
2+
import { SponsoredFeePaymentMethod } from "@aztec/aztec.js/fee/testing";
3+
import { Fr } from "@aztec/aztec.js/fields";
4+
import { AztecAddress } from "@aztec/stdlib/aztec-address";
25
import { PrivateVotingContract } from "../src/artifacts/PrivateVoting.js";
36
import { SponsoredFPCContract } from "@aztec/noir-contracts.js/SponsoredFPC";
4-
import { setupPXE } from "../src/utils/setup_wallet.js";
7+
import { setupWallet } from "../src/utils/setup_wallet.js";
58
import { getSponsoredFPCInstance } from "../src/utils/sponsored_fpc.js";
69
import { getAccountFromEnv } from "../src/utils/create_account_from_env.js";
710
import { getTimeouts } from "../config/config.js";
@@ -12,17 +15,17 @@ async function main() {
1215

1316
const timeouts = getTimeouts();
1417

15-
// Setup PXE
16-
const pxe = await setupPXE();
18+
// Setup wallet
19+
const wallet = await setupWallet();
1720

1821
// Setup sponsored fee payment
1922
const sponsoredFPC = await getSponsoredFPCInstance();
20-
await pxe.registerContract({ instance: sponsoredFPC, artifact: SponsoredFPCContract.artifact });
23+
await wallet.registerContract({ instance: sponsoredFPC, artifact: SponsoredFPCContract.artifact });
2124
const sponsoredPaymentMethod = new SponsoredFeePaymentMethod(sponsoredFPC.address);
2225

2326
// Get account from environment variables
24-
const accountManager = await getAccountFromEnv(pxe);
25-
const wallet = await accountManager.getWallet();
27+
const accountManager = await getAccountFromEnv(wallet);
28+
const address = accountManager.address;
2629

2730
// Connect to existing voting contract (replace with your deployed contract address)
2831
const contractAddress = process.env.VOTING_CONTRACT_ADDRESS;
@@ -43,15 +46,15 @@ async function main() {
4346
// First get_vote call - check initial vote count
4447
logger.info("Getting initial vote count...");
4548
const initialVoteCount = await votingContract.methods.get_vote(candidate).simulate({
46-
from: wallet.getAddress()
49+
from: address
4750
});
4851
logger.info(`Initial vote count for candidate ${candidate}: ${initialVoteCount}`);
4952

5053
// Cast a vote
5154
logger.info("Casting vote...");
5255
await votingContract.methods.cast_vote(candidate)
5356
.send({
54-
from: wallet.getAddress(),
57+
from: address,
5558
fee: { paymentMethod: sponsoredPaymentMethod }
5659
})
5760
.wait({ timeout: timeouts.txTimeout });
@@ -60,7 +63,7 @@ async function main() {
6063
// Second get_vote call - check updated vote count
6164
logger.info("Getting updated vote count...");
6265
const updatedVoteCount = await votingContract.methods.get_vote(candidate).simulate({
63-
from: wallet.getAddress()
66+
from: address
6467
});
6568
logger.info(`Updated vote count for candidate ${candidate}: ${updatedVoteCount}`);
6669

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
1-
import { waitForPXE, getContractInstanceFromInstantiationParams, Fr, ContractInstanceWithAddress, AztecAddress, SponsoredFeePaymentMethod, createAztecNodeClient, Fq } from "@aztec/aztec.js";
1+
import { Fr, GrumpkinScalar } from "@aztec/aztec.js/fields";
2+
import { getContractInstanceFromInstantiationParams } from "@aztec/aztec.js/contracts";
3+
import { ContractInstanceWithAddress } from "@aztec/stdlib/contract";
4+
import { AztecAddress } from "@aztec/stdlib/aztec-address";
5+
import { SponsoredFeePaymentMethod } from "@aztec/aztec.js/fee/testing";
6+
import { createAztecNodeClient } from "@aztec/aztec.js/node";
27
import { TokenContract } from "@aztec/noir-contracts.js/Token"
38
import { getSponsoredFPCInstance } from "../src/utils/sponsored_fpc.js";
4-
import { getSchnorrAccount } from "@aztec/accounts/schnorr";
59
import { SponsoredFPCContract } from "@aztec/noir-contracts.js/SponsoredFPC";
6-
import { createPXEService, getPXEServiceConfig } from '@aztec/pxe/server';
7-
import { createStore } from "@aztec/kv-store/lmdb"
10+
import { getPXEConfig } from "@aztec/pxe/config";
11+
import { createStore } from "@aztec/kv-store/lmdb"
812
import { getEnv, getAztecNodeUrl } from "../config/config.js";
13+
import { TestWallet } from "@aztec/test-wallet/server";
914

1015
const nodeUrl = getAztecNodeUrl();
1116
const node = createAztecNodeClient(nodeUrl)
1217
const l1Contracts = await node.getL1ContractAddresses();
13-
const config = getPXEServiceConfig()
18+
const config = getPXEConfig()
1419
const fullConfig = { ...config, l1Contracts }
1520
fullConfig.proverEnabled = getEnv() !== 'sandbox';
1621

1722
const store1 = await createStore('pxe1', {
1823
dataDirectory: 'store',
19-
dataStoreMapSizeKB: 1e6,
24+
dataStoreMapSizeKb: 1e6,
2025
});
2126

2227
const store2 = await createStore('pxe2', {
2328
dataDirectory: 'store',
24-
dataStoreMapSizeKB: 1e6,
29+
dataStoreMapSizeKb: 1e6,
2530
});
2631

27-
const setupPxe1 = async () => {
28-
const pxe = await createPXEService(node, fullConfig, { store: store1 });
29-
await waitForPXE(pxe);
30-
return pxe;
32+
const setupWallet1 = async () => {
33+
return await TestWallet.create(node, fullConfig, { store: store1 });
3134
};
3235

33-
const setupPxe2 = async () => {
34-
const pxe = await createPXEService(node, fullConfig, { store: store2 });
35-
await waitForPXE(pxe);
36-
return pxe;
36+
const setupWallet2 = async () => {
37+
return await TestWallet.create(node, fullConfig, { store: store2 });
3738
};
3839

3940
const L2_TOKEN_CONTRACT_SALT = Fr.random();
@@ -56,49 +57,48 @@ export async function getL2TokenContractInstance(deployerAddress: any, ownerAzte
5657

5758
async function main() {
5859

59-
const pxe1 = await setupPxe1();
60-
const pxe2 = await setupPxe2();
60+
const wallet1 = await setupWallet1();
61+
const wallet2 = await setupWallet2();
6162
const sponsoredFPC = await getSponsoredFPCInstance();
62-
await pxe1.registerContract({ instance: sponsoredFPC, artifact: SponsoredFPCContract.artifact });
63-
await pxe2.registerContract({ instance: sponsoredFPC, artifact: SponsoredFPCContract.artifact });
63+
await wallet1.registerContract({ instance: sponsoredFPC, artifact: SponsoredFPCContract.artifact });
64+
await wallet2.registerContract({ instance: sponsoredFPC, artifact: SponsoredFPCContract.artifact });
6465
const paymentMethod = new SponsoredFeePaymentMethod(sponsoredFPC.address);
6566
// deploy token contract
6667

6768
let secretKey = Fr.random();
68-
let signingKey = Fq.random();
69+
let signingKey = GrumpkinScalar.random();
6970
let salt = Fr.random();
70-
let schnorrAccount = await getSchnorrAccount(pxe1, secretKey, signingKey, salt);
71-
let tx = await schnorrAccount.deploy({ fee: { paymentMethod } }).wait();
72-
let ownerWallet = await schnorrAccount.getWallet();
73-
let ownerAddress = ownerWallet.getAddress();
74-
const token = await TokenContract.deploy(ownerWallet, ownerAddress, 'Clean USDC', 'USDC', 6).send({
71+
let schnorrAccount = await wallet1.createSchnorrAccount(secretKey, salt, signingKey);
72+
let tx = await (await schnorrAccount.getDeployMethod()).send({ from: AztecAddress.ZERO, fee: { paymentMethod } }).wait();
73+
let ownerAddress = schnorrAccount.address;
74+
const token = await TokenContract.deploy(wallet1, ownerAddress, 'Clean USDC', 'USDC', 6).send({
7575
from: ownerAddress,
7676
contractAddressSalt: L2_TOKEN_CONTRACT_SALT,
7777
fee: { paymentMethod }
7878
}).wait()
7979

8080
// setup account on 2nd pxe
8181

82-
await pxe2.registerSender(ownerAddress)
82+
await wallet2.registerSender(ownerAddress)
8383

8484
let secretKey2 = Fr.random();
85-
let signingKey2 = Fq.random();
85+
let signingKey2 = GrumpkinScalar.random();
8686
let salt2 = Fr.random();
87-
let schnorrAccount2 = await getSchnorrAccount(pxe2, secretKey2, signingKey2, salt2);
87+
let schnorrAccount2 = await wallet2.createSchnorrAccount(secretKey2, salt2, signingKey2);
8888

8989
// deploy account on 2nd pxe
90-
let tx2 = await schnorrAccount2.deploy({ fee: { paymentMethod } }).wait();
91-
let wallet2 = await schnorrAccount2.getWallet();
90+
let tx2 = await (await schnorrAccount2.getDeployMethod()).send({ from: AztecAddress.ZERO, fee: { paymentMethod } }).wait();
91+
let wallet2Address = schnorrAccount2.address;
9292
await wallet2.registerSender(ownerAddress)
9393

9494
// mint to account on 2nd pxe
9595

96-
const private_mint_tx = await token.contract.methods.mint_to_private(schnorrAccount2.getAddress(), 100).send({
96+
const private_mint_tx = await token.contract.methods.mint_to_private(schnorrAccount2.address, 100).send({
9797
from: ownerAddress,
9898
fee: { paymentMethod }
9999
}).wait()
100-
console.log(await pxe1.getTxEffect(private_mint_tx.txHash))
101-
await token.contract.methods.mint_to_public(schnorrAccount2.getAddress(), 100).send({
100+
console.log(await node.getTxEffect(private_mint_tx.txHash))
101+
await token.contract.methods.mint_to_public(schnorrAccount2.address, 100).send({
102102
from: ownerAddress,
103103
fee: { paymentMethod }
104104
}).wait()
@@ -118,20 +118,20 @@ async function main() {
118118
)
119119

120120
await l2TokenContract.methods.sync_private_state().simulate({
121-
from: wallet2.getAddress()
121+
from: wallet2Address
122122
})
123123

124-
const notes = await pxe2.getNotes({ txHash: private_mint_tx.txHash, contractAddress: l2TokenContractInstance.address });
124+
const notes = await wallet2.getNotes({ contractAddress: l2TokenContractInstance.address });
125125
console.log(notes)
126126

127127
// returns 0n
128-
const balance = await l2TokenContract.methods.balance_of_private(wallet2.getAddress()).simulate({
129-
from: wallet2.getAddress()
128+
const balance = await l2TokenContract.methods.balance_of_private(wallet2Address).simulate({
129+
from: wallet2Address
130130
})
131131
console.log("private balance should be 100", balance)
132132
// errors
133-
await l2TokenContract.methods.balance_of_public(wallet2.getAddress()).simulate({
134-
from: wallet2.getAddress()
133+
await l2TokenContract.methods.balance_of_public(wallet2Address).simulate({
134+
from: wallet2Address
135135
})
136136

137137
}

scripts/profile_deploy.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
import { PrivateVotingContract } from "../src/artifacts/PrivateVoting.js"
2-
import { createLogger, PXE, Logger, SponsoredFeePaymentMethod, Fr } from "@aztec/aztec.js";
3-
import { setupPXE } from "../src/utils/setup_wallet.js";
2+
import { Logger, createLogger } from "@aztec/aztec.js/log";
3+
import { setupWallet } from "../src/utils/setup_wallet.js";
44
import { getSponsoredFPCInstance } from "../src/utils/sponsored_fpc.js";
55
import { SponsoredFPCContract } from "@aztec/noir-contracts.js/SponsoredFPC";
66
import { deploySchnorrAccount } from "../src/utils/deploy_account.js";
77

88
async function main() {
99

10-
let pxe: PXE;
1110
let logger: Logger;
1211

1312
logger = createLogger('aztec:aztec-starter');
1413

15-
pxe = await setupPXE();
14+
const wallet = await setupWallet();
1615

1716
const sponsoredFPC = await getSponsoredFPCInstance();
18-
await pxe.registerContract({ instance: sponsoredFPC, artifact: SponsoredFPCContract.artifact });
17+
await wallet.registerContract({ instance: sponsoredFPC, artifact: SponsoredFPCContract.artifact });
1918

20-
let accountManager = await deploySchnorrAccount(pxe);
21-
const wallet = await accountManager.getWallet();
22-
const address = await accountManager.getAddress();
19+
let accountManager = await deploySchnorrAccount(wallet);
20+
const address = accountManager.address;
2321

2422
const profileTx = await PrivateVotingContract.deploy(wallet, address).profile({ profileMode: "full", from: address });
2523
console.dir(profileTx, { depth: 2 });

src/utils/create_account_from_env.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import { AccountManager } from "@aztec/aztec.js/wallet";
44
import { PXE } from "@aztec/pxe/client/bundle";
55
import { setupWallet } from "./setup_wallet.js";
66
import * as dotenv from 'dotenv';
7+
import { TestWallet } from "@aztec/test-wallet/server";
78

89
// Load environment variables
910
dotenv.config();
1011

11-
export async function createAccountFromEnv(pxe: PXE): Promise<AccountManager> {
12+
export async function createAccountFromEnv(wallet: TestWallet): Promise<AccountManager> {
1213
let logger: Logger;
1314
logger = createLogger('aztec:create-account');
14-
const wallet = await setupWallet();
1515

1616
logger.info('🔐 Creating Schnorr account from environment variables...');
1717

@@ -56,8 +56,8 @@ export async function createAccountFromEnv(pxe: PXE): Promise<AccountManager> {
5656
// Check if account is already deployed
5757
logger.info('🔍 Checking if account is already deployed...');
5858
try {
59-
const registeredAccounts = await pxe.getRegisteredAccounts();
60-
const isRegistered = registeredAccounts.some(acc => acc.address.equals(accountAddress));
59+
const registeredAccounts = await wallet.getAccounts();
60+
const isRegistered = registeredAccounts.some(acc => acc.item.equals(accountAddress));
6161

6262
if (isRegistered) {
6363
logger.info('✅ Account is already registered with PXE');
@@ -77,6 +77,6 @@ export async function createAccountFromEnv(pxe: PXE): Promise<AccountManager> {
7777
return schnorrAccount;
7878
}
7979

80-
export async function getAccountFromEnv(pxe: PXE): Promise<AccountManager> {
81-
return await createAccountFromEnv(pxe);
80+
export async function getAccountFromEnv(wallet: TestWallet): Promise<AccountManager> {
81+
return await createAccountFromEnv(wallet);
8282
}

0 commit comments

Comments
 (0)