@aztec/cli 0.16.1 → 0.16.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/dest/bin/index.js +4 -3
  2. package/dest/cmds/add_contract.d.ts +7 -0
  3. package/dest/cmds/add_contract.d.ts.map +1 -0
  4. package/dest/cmds/add_contract.js +15 -0
  5. package/dest/cmds/add_note.d.ts +8 -0
  6. package/dest/cmds/add_note.d.ts.map +1 -0
  7. package/dest/cmds/add_note.js +13 -0
  8. package/dest/cmds/block_number.d.ts +6 -0
  9. package/dest/cmds/block_number.d.ts.map +1 -0
  10. package/dest/cmds/block_number.js +10 -0
  11. package/dest/cmds/call.d.ts +7 -0
  12. package/dest/cmds/call.d.ts.map +1 -0
  13. package/dest/cmds/call.js +18 -0
  14. package/dest/cmds/check_deploy.d.ts +7 -0
  15. package/dest/cmds/check_deploy.d.ts.map +1 -0
  16. package/dest/cmds/check_deploy.js +16 -0
  17. package/dest/cmds/compute_selector.d.ts +6 -0
  18. package/dest/cmds/compute_selector.d.ts.map +1 -0
  19. package/dest/cmds/compute_selector.js +9 -0
  20. package/dest/cmds/create_account.d.ts +7 -0
  21. package/dest/cmds/create_account.d.ts.map +1 -0
  22. package/dest/cmds/create_account.js +30 -0
  23. package/dest/cmds/deploy.d.ts +7 -0
  24. package/dest/cmds/deploy.d.ts.map +1 -0
  25. package/dest/cmds/deploy.js +58 -0
  26. package/dest/cmds/deploy_l1_contracts.d.ts +6 -0
  27. package/dest/cmds/deploy_l1_contracts.d.ts.map +1 -0
  28. package/dest/cmds/deploy_l1_contracts.js +15 -0
  29. package/dest/cmds/example_contracts.d.ts +6 -0
  30. package/dest/cmds/example_contracts.d.ts.map +1 -0
  31. package/dest/cmds/example_contracts.js +10 -0
  32. package/dest/cmds/generate_p2p_private_key.d.ts +6 -0
  33. package/dest/cmds/generate_p2p_private_key.d.ts.map +1 -0
  34. package/dest/cmds/generate_p2p_private_key.js +11 -0
  35. package/dest/cmds/generate_private_key.d.ts +6 -0
  36. package/dest/cmds/generate_private_key.d.ts.map +1 -0
  37. package/dest/cmds/generate_private_key.js +22 -0
  38. package/dest/cmds/get_account.d.ts +7 -0
  39. package/dest/cmds/get_account.d.ts.map +1 -0
  40. package/dest/cmds/get_account.js +15 -0
  41. package/dest/cmds/get_accounts.d.ts +6 -0
  42. package/dest/cmds/get_accounts.d.ts.map +1 -0
  43. package/dest/cmds/get_accounts.js +18 -0
  44. package/dest/cmds/get_contract_data.d.ts +7 -0
  45. package/dest/cmds/get_contract_data.d.ts.map +1 -0
  46. package/dest/cmds/get_contract_data.js +28 -0
  47. package/dest/cmds/get_logs.d.ts +7 -0
  48. package/dest/cmds/get_logs.d.ts.map +1 -0
  49. package/dest/cmds/get_logs.js +54 -0
  50. package/dest/cmds/get_node_info.d.ts +6 -0
  51. package/dest/cmds/get_node_info.d.ts.map +1 -0
  52. package/dest/cmds/get_node_info.js +15 -0
  53. package/dest/cmds/get_recipient.d.ts +7 -0
  54. package/dest/cmds/get_recipient.d.ts.map +1 -0
  55. package/dest/cmds/get_recipient.js +15 -0
  56. package/dest/cmds/get_recipients.d.ts +6 -0
  57. package/dest/cmds/get_recipients.d.ts.map +1 -0
  58. package/dest/cmds/get_recipients.js +18 -0
  59. package/dest/cmds/get_tx_receipt.d.ts +7 -0
  60. package/dest/cmds/get_tx_receipt.d.ts.map +1 -0
  61. package/dest/cmds/get_tx_receipt.js +16 -0
  62. package/dest/cmds/inspect_contract.d.ts +6 -0
  63. package/dest/cmds/inspect_contract.d.ts.map +1 -0
  64. package/dest/cmds/inspect_contract.js +19 -0
  65. package/dest/cmds/parse_parameter_struct.d.ts +6 -0
  66. package/dest/cmds/parse_parameter_struct.d.ts.map +1 -0
  67. package/dest/cmds/parse_parameter_struct.js +20 -0
  68. package/dest/cmds/register_account.d.ts +7 -0
  69. package/dest/cmds/register_account.d.ts.map +1 -0
  70. package/dest/cmds/register_account.js +13 -0
  71. package/dest/cmds/register_recipient.d.ts +7 -0
  72. package/dest/cmds/register_recipient.d.ts.map +1 -0
  73. package/dest/cmds/register_recipient.js +11 -0
  74. package/dest/cmds/send.d.ts +7 -0
  75. package/dest/cmds/send.d.ts.map +1 -0
  76. package/dest/cmds/send.js +26 -0
  77. package/dest/cmds/unbox.d.ts +6 -0
  78. package/dest/cmds/unbox.d.ts.map +1 -0
  79. package/dest/cmds/unbox.js +9 -0
  80. package/dest/index.d.ts.map +1 -1
  81. package/dest/index.js +65 -312
  82. package/dest/utils.d.ts +9 -5
  83. package/dest/utils.d.ts.map +1 -1
  84. package/dest/utils.js +14 -10
  85. package/package.json +8 -8
  86. package/src/bin/index.ts +4 -2
  87. package/src/cmds/add_contract.ts +27 -0
  88. package/src/cmds/add_note.ts +24 -0
  89. package/src/cmds/block_number.ts +12 -0
  90. package/src/cmds/call.ts +35 -0
  91. package/src/cmds/check_deploy.ts +17 -0
  92. package/src/cmds/compute_selector.ts +10 -0
  93. package/src/cmds/create_account.ts +39 -0
  94. package/src/cmds/deploy.ts +77 -0
  95. package/src/cmds/deploy_l1_contracts.ts +25 -0
  96. package/src/cmds/example_contracts.ts +12 -0
  97. package/src/cmds/generate_p2p_private_key.ts +13 -0
  98. package/src/cmds/generate_private_key.ts +23 -0
  99. package/src/cmds/get_account.ts +18 -0
  100. package/src/cmds/get_accounts.ts +19 -0
  101. package/src/cmds/get_contract_data.ts +39 -0
  102. package/src/cmds/get_logs.ts +71 -0
  103. package/src/cmds/get_node_info.ts +17 -0
  104. package/src/cmds/get_recipient.ts +18 -0
  105. package/src/cmds/get_recipients.ts +19 -0
  106. package/src/cmds/get_tx_receipt.ts +18 -0
  107. package/src/cmds/inspect_contract.ts +29 -0
  108. package/src/cmds/parse_parameter_struct.ts +30 -0
  109. package/src/cmds/register_account.ts +24 -0
  110. package/src/cmds/register_recipient.ts +21 -0
  111. package/src/cmds/send.ts +40 -0
  112. package/src/cmds/unbox.ts +11 -0
  113. package/src/index.ts +97 -358
  114. package/src/utils.ts +28 -22
package/src/index.ts CHANGED
@@ -1,50 +1,16 @@
1
- import {
2
- AztecAddress,
3
- Contract,
4
- ContractDeployer,
5
- EthAddress,
6
- Fr,
7
- GrumpkinScalar,
8
- Note,
9
- generatePublicKey,
10
- getSchnorrAccount,
11
- isContractDeployed,
12
- } from '@aztec/aztec.js';
13
- import {
14
- FunctionSelector,
15
- StructType,
16
- decodeFunctionSignature,
17
- decodeFunctionSignatureWithParameterNames,
18
- } from '@aztec/foundation/abi';
19
- import { JsonStringify } from '@aztec/foundation/json-rpc';
1
+ import { initAztecJs } from '@aztec/aztec.js/init';
20
2
  import { DebugLogger, LogFn } from '@aztec/foundation/log';
21
- import { sleep } from '@aztec/foundation/sleep';
22
3
  import { fileURLToPath } from '@aztec/foundation/url';
23
- import { compileNoir, generateNoirInterface, generateTypescriptInterface } from '@aztec/noir-compiler/cli';
24
- import { CompleteAddress, ContractData, ExtendedNote, LogFilter } from '@aztec/types';
4
+ import { addNoirCompilerCommanderActions } from '@aztec/noir-compiler/cli';
25
5
 
26
- import { createSecp256k1PeerId } from '@libp2p/peer-id-factory';
27
6
  import { Command, Option } from 'commander';
28
7
  import { readFileSync } from 'fs';
29
8
  import { dirname, resolve } from 'path';
30
- import { format } from 'util';
31
- import { mnemonicToAccount } from 'viem/accounts';
32
-
33
- import { createCompatibleClient } from './client.js';
34
- import { encodeArgs, parseStructString } from './encoding.js';
35
- import { GITHUB_TAG_PREFIX } from './github.js';
36
- import { unboxContract } from './unbox.js';
37
- import { update } from './update/update.js';
9
+
38
10
  import {
39
- deployAztecContracts,
40
- getContractArtifact,
41
- getExampleContractArtifacts,
42
- getFunctionArtifact,
43
- getTxSender,
44
11
  parseAztecAddress,
45
12
  parseEthereumAddress,
46
13
  parseField,
47
- parseFields,
48
14
  parseOptionalAztecAddress,
49
15
  parseOptionalInteger,
50
16
  parseOptionalLogId,
@@ -55,11 +21,8 @@ import {
55
21
  parsePublicKey,
56
22
  parseSaltFromHexString,
57
23
  parseTxHash,
58
- prepTx,
59
24
  } from './utils.js';
60
25
 
61
- const accountCreationSalt = Fr.ZERO;
62
-
63
26
  const { ETHEREUM_HOST = 'http://localhost:8545', PRIVATE_KEY, API_KEY } = process.env;
64
27
 
65
28
  /**
@@ -73,6 +36,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
73
36
 
74
37
  const packageJsonPath = resolve(dirname(fileURLToPath(import.meta.url)), '../package.json');
75
38
  const cliVersion: string = JSON.parse(readFileSync(packageJsonPath).toString()).version;
39
+ const logJson = (obj: object) => log(JSON.stringify(obj, null, 2));
76
40
 
77
41
  program.name('aztec-cli').description('CLI for interacting with Aztec.').version(cliVersion);
78
42
 
@@ -87,6 +51,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
87
51
  .argParser(parsePrivateKey)
88
52
  .makeOptionMandatory(mandatory);
89
53
 
54
+ program.hook('preAction', initAztecJs);
55
+
90
56
  program
91
57
  .command('deploy-l1-contracts')
92
58
  .description('Deploys all necessary Ethereum contracts for Aztec.')
@@ -103,20 +69,15 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
103
69
  'test test test test test test test test test test test junk',
104
70
  )
105
71
  .action(async options => {
106
- const { l1ContractAddresses } = await deployAztecContracts(
72
+ const { deployL1Contracts } = await import('./cmds/deploy_l1_contracts.js');
73
+ await deployL1Contracts(
107
74
  options.rpcUrl,
108
75
  options.apiKey ?? '',
109
76
  options.privateKey,
110
77
  options.mnemonic,
78
+ log,
111
79
  debugLogger,
112
80
  );
113
- log('\n');
114
- log(`Rollup Address: ${l1ContractAddresses.rollupAddress.toString()}`);
115
- log(`Registry Address: ${l1ContractAddresses.registryAddress.toString()}`);
116
- log(`L1 -> L2 Inbox Address: ${l1ContractAddresses.inboxAddress.toString()}`);
117
- log(`L2 -> L1 Outbox address: ${l1ContractAddresses.outboxAddress.toString()}`);
118
- log(`Contract Deployment Emitter Address: ${l1ContractAddresses.contractDeploymentEmitterAddress.toString()}`);
119
- log('\n');
120
81
  });
121
82
 
122
83
  program
@@ -129,20 +90,9 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
129
90
  '-m, --mnemonic',
130
91
  'An optional mnemonic string used for the private key generation. If not provided, random private key will be generated.',
131
92
  )
132
- .action(options => {
133
- let privKey;
134
- let publicKey;
135
- if (options.mnemonic) {
136
- const acc = mnemonicToAccount(options.mnemonic);
137
- // TODO(#2052): This reduction is not secure enough. TACKLE THIS ISSUE BEFORE MAINNET.
138
- const key = GrumpkinScalar.fromBufferReduce(Buffer.from(acc.getHdKey().privateKey!));
139
- publicKey = generatePublicKey(key);
140
- } else {
141
- const key = GrumpkinScalar.random();
142
- privKey = key.toString();
143
- publicKey = generatePublicKey(key);
144
- }
145
- log(`\nPrivate Key: ${privKey}\nPublic Key: ${publicKey.toString()}\n`);
93
+ .action(async options => {
94
+ const { generatePrivateKey } = await import('./cmds/generate_private_key.js');
95
+ generatePrivateKey(options.mnemonic, log);
146
96
  });
147
97
 
148
98
  program
@@ -150,10 +100,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
150
100
  .summary('Generates a LibP2P peer private key.')
151
101
  .description('Generates a private key that can be used for running a node on a LibP2P network.')
152
102
  .action(async () => {
153
- const peerId = await createSecp256k1PeerId();
154
- const exportedPeerId = Buffer.from(peerId.privateKey!).toString('hex');
155
- log(`Private key: ${exportedPeerId}`);
156
- log(`Peer Id: ${peerId}`);
103
+ const { generateP2PPrivateKey } = await import('./cmds/generate_p2p_private_key.js');
104
+ await generateP2PPrivateKey(log);
157
105
  });
158
106
 
159
107
  program
@@ -170,28 +118,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
170
118
  // https://github.com/tj/commander.js#other-option-types-negatable-boolean-and-booleanvalue
171
119
  .option('--no-wait', 'Skip waiting for the contract to be deployed. Print the hash of deployment transaction')
172
120
  .action(async ({ rpcUrl, privateKey, wait }) => {
173
- const client = await createCompatibleClient(rpcUrl, debugLogger);
174
- const actualPrivateKey = privateKey ?? GrumpkinScalar.random();
175
-
176
- const account = getSchnorrAccount(client, actualPrivateKey, actualPrivateKey, accountCreationSalt);
177
- const { address, publicKey, partialAddress } = account.getCompleteAddress();
178
- const tx = await account.deploy();
179
- const txHash = await tx.getTxHash();
180
- debugLogger(`Account contract tx sent with hash ${txHash}`);
181
- if (wait) {
182
- log(`\nWaiting for account contract deployment...`);
183
- await tx.wait();
184
- } else {
185
- log(`\nAccount deployment transaction hash: ${txHash}\n`);
186
- }
187
-
188
- log(`\nNew account:\n`);
189
- log(`Address: ${address.toString()}`);
190
- log(`Public key: ${publicKey.toString()}`);
191
- if (!privateKey) {
192
- log(`Private key: ${actualPrivateKey.toString()}`);
193
- }
194
- log(`Partial address: ${partialAddress.toString()}`);
121
+ const { createAccount } = await import('./cmds/create_account.js');
122
+ await createAccount(rpcUrl, privateKey, wait, debugLogger, log);
195
123
  });
196
124
 
197
125
  program
@@ -208,14 +136,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
208
136
  )
209
137
  .addOption(pxeOption)
210
138
  .action(async ({ rpcUrl, privateKey, partialAddress }) => {
211
- const client = await createCompatibleClient(rpcUrl, debugLogger);
212
-
213
- const { address, publicKey } = await client.registerAccount(privateKey, partialAddress);
214
-
215
- log(`\nRegistered account:\n`);
216
- log(`Address: ${address.toString()}`);
217
- log(`Public key: ${publicKey.toString()}`);
218
- log(`Partial address: ${partialAddress.toString()}`);
139
+ const { registerAccount } = await import('./cmds/register_account.js');
140
+ await registerAccount(rpcUrl, privateKey, partialAddress, debugLogger, log);
219
141
  });
220
142
 
221
143
  program
@@ -242,48 +164,25 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
242
164
  'Optional deployment salt as a hex string for generating the deployment address.',
243
165
  parseSaltFromHexString,
244
166
  )
167
+ .option('--json', 'Emit output as json')
245
168
  // `options.wait` is default true. Passing `--no-wait` will set it to false.
246
169
  // https://github.com/tj/commander.js#other-option-types-negatable-boolean-and-booleanvalue
247
170
  .option('--no-wait', 'Skip waiting for the contract to be deployed. Print the hash of deployment transaction')
248
- .action(async (artifactPath, { rpcUrl, publicKey, args: rawArgs, portalAddress, salt, wait }) => {
249
- const contractArtifact = await getContractArtifact(artifactPath, log);
250
- const constructorArtifact = contractArtifact.functions.find(({ name }) => name === 'constructor');
251
-
252
- const client = await createCompatibleClient(rpcUrl, debugLogger);
253
- const nodeInfo = await client.getNodeInfo();
254
- const expectedAztecNrVersion = `${GITHUB_TAG_PREFIX}-v${nodeInfo.sandboxVersion}`;
255
- if (contractArtifact.aztecNrVersion && contractArtifact.aztecNrVersion !== expectedAztecNrVersion) {
256
- log(
257
- `\nWarning: Contract was compiled with a different version of Aztec.nr: ${contractArtifact.aztecNrVersion}. Consider updating Aztec.nr to ${expectedAztecNrVersion}\n`,
258
- );
259
- }
260
-
261
- const deployer = new ContractDeployer(contractArtifact, client, publicKey);
262
-
263
- const constructor = getFunctionArtifact(contractArtifact, 'constructor');
264
- if (!constructor) {
265
- throw new Error(`Constructor not found in contract ABI`);
266
- }
267
-
268
- debugLogger(`Input arguments: ${rawArgs.map((x: any) => `"${x}"`).join(', ')}`);
269
- const args = encodeArgs(rawArgs, constructorArtifact!.parameters);
270
- debugLogger(`Encoded arguments: ${args.join(', ')}`);
271
-
272
- const deploy = deployer.deploy(...args);
273
-
274
- await deploy.create({ contractAddressSalt: salt, portalContract: portalAddress });
275
- const tx = deploy.send({ contractAddressSalt: salt, portalContract: portalAddress });
276
- const txHash = await tx.getTxHash();
277
- debugLogger(`Deploy tx sent with hash ${txHash}`);
278
- if (wait) {
279
- const deployed = await tx.wait();
280
- log(`\nContract deployed at ${deployed.contract.completeAddress.address.toString()}\n`);
281
- log(`Contract partial address ${deployed.contract.completeAddress.partialAddress.toString()}\n`);
282
- } else {
283
- log(`\nContract Address: ${deploy.completeAddress?.address.toString() ?? 'N/A'}`);
284
- log(`Contract Partial Address: ${deploy.completeAddress?.partialAddress.toString() ?? 'N/A'}`);
285
- log(`Deployment transaction hash: ${txHash}\n`);
286
- }
171
+ .action(async (artifactPath, { json, rpcUrl, publicKey, args: rawArgs, portalAddress, salt, wait }) => {
172
+ const { deploy } = await import('./cmds/deploy.js');
173
+ await deploy(
174
+ artifactPath,
175
+ json,
176
+ rpcUrl,
177
+ publicKey,
178
+ rawArgs,
179
+ portalAddress,
180
+ salt,
181
+ wait,
182
+ debugLogger,
183
+ log,
184
+ logJson,
185
+ );
287
186
  });
288
187
 
289
188
  program
@@ -296,14 +195,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
296
195
  )
297
196
  .addOption(pxeOption)
298
197
  .action(async options => {
299
- const client = await createCompatibleClient(options.rpcUrl, debugLogger);
300
- const address = options.contractAddress;
301
- const isDeployed = await isContractDeployed(client, address);
302
- if (isDeployed) {
303
- log(`\nContract found at ${address.toString()}\n`);
304
- } else {
305
- log(`\nNo contract found at ${address.toString()}\n`);
306
- }
198
+ const { checkDeploy } = await import('./cmds/check_deploy.js');
199
+ await checkDeploy(options.rpcUrl, options.contractAddress, debugLogger, log);
307
200
  });
308
201
 
309
202
  program
@@ -321,32 +214,27 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
321
214
  .option('--portal-address <address>', 'Optional address to a portal contract on L1', parseEthereumAddress)
322
215
  .addOption(pxeOption)
323
216
  .action(async options => {
324
- const artifact = await getContractArtifact(options.contractArtifact, log);
325
- const contractAddress: AztecAddress = options.contractAddress;
326
- const completeAddress = new CompleteAddress(
327
- contractAddress,
328
- options.publicKey ?? Fr.ZERO,
217
+ const { addContract } = await import('./cmds/add_contract.js');
218
+ await addContract(
219
+ options.rpcUrl,
220
+ options.contractArtifact,
221
+ options.contractAddress,
329
222
  options.partialAddress,
223
+ options.publicKey,
224
+ options.portalContract,
225
+ debugLogger,
226
+ log,
330
227
  );
331
- const portalContract: EthAddress = options.portalContract ?? EthAddress.ZERO;
332
- const client = await createCompatibleClient(options.rpcUrl, debugLogger);
333
-
334
- await client.addContracts([{ artifact, completeAddress, portalContract }]);
335
- log(`\nContract added to PXE at ${contractAddress.toString()}\n`);
336
228
  });
229
+
337
230
  program
338
231
  .command('get-tx-receipt')
339
232
  .description('Gets the receipt for the specified transaction hash.')
340
233
  .argument('<txHash>', 'A transaction hash to get the receipt for.', parseTxHash)
341
234
  .addOption(pxeOption)
342
235
  .action(async (txHash, options) => {
343
- const client = await createCompatibleClient(options.rpcUrl, debugLogger);
344
- const receipt = await client.getTxReceipt(txHash);
345
- if (!receipt) {
346
- log(`No receipt found for transaction hash ${txHash.toString()}`);
347
- } else {
348
- log(`\nTransaction receipt: \n${JsonStringify(receipt, true)}\n`);
349
- }
236
+ const { getTxReceipt } = await import('./cmds/get_tx_receipt.js');
237
+ await getTxReceipt(options.rpcUrl, txHash, debugLogger, log);
350
238
  });
351
239
 
352
240
  program
@@ -356,28 +244,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
356
244
  .addOption(pxeOption)
357
245
  .option('-b, --include-bytecode <boolean>', "Include the contract's public function bytecode, if any.", false)
358
246
  .action(async (contractAddress, options) => {
359
- const client = await createCompatibleClient(options.rpcUrl, debugLogger);
360
- const contractDataWithOrWithoutBytecode = options.includeBytecode
361
- ? await client.getExtendedContractData(contractAddress)
362
- : await client.getContractData(contractAddress);
363
-
364
- if (!contractDataWithOrWithoutBytecode) {
365
- log(`No contract data found at ${contractAddress}`);
366
- return;
367
- }
368
- let contractData: ContractData;
369
-
370
- if ('contractData' in contractDataWithOrWithoutBytecode) {
371
- contractData = contractDataWithOrWithoutBytecode.contractData;
372
- } else {
373
- contractData = contractDataWithOrWithoutBytecode;
374
- }
375
- log(`\nContract Data: \nAddress: ${contractData.contractAddress.toString()}`);
376
- log(`Portal: ${contractData.portalContractAddress.toString()}`);
377
- if ('bytecode' in contractDataWithOrWithoutBytecode) {
378
- log(`Bytecode: ${contractDataWithOrWithoutBytecode.bytecode}`);
379
- }
380
- log('\n');
247
+ const { getContractData } = await import('./cmds/get_contract_data.js');
248
+ await getContractData(options.rpcUrl, contractAddress, options.includeBytecode, debugLogger, log);
381
249
  });
382
250
 
383
251
  program
@@ -396,55 +264,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
396
264
  .addOption(pxeOption)
397
265
  .option('--follow', 'If set, will keep polling for new logs until interrupted.')
398
266
  .action(async ({ txHash, fromBlock, toBlock, afterLog, contractAddress, selector, rpcUrl, follow }) => {
399
- const pxe = await createCompatibleClient(rpcUrl, debugLogger);
400
-
401
- if (follow) {
402
- if (txHash) {
403
- throw Error('Cannot use --follow with --tx-hash');
404
- }
405
- if (toBlock) {
406
- throw Error('Cannot use --follow with --to-block');
407
- }
408
- }
409
-
410
- const filter: LogFilter = { txHash, fromBlock, toBlock, afterLog, contractAddress, selector };
411
-
412
- const fetchLogs = async () => {
413
- const response = await pxe.getUnencryptedLogs(filter);
414
- const logs = response.logs;
415
-
416
- if (!logs.length) {
417
- const filterOptions = Object.entries(filter)
418
- .filter(([, value]) => value !== undefined)
419
- .map(([key, value]) => `${key}: ${value}`)
420
- .join(', ');
421
- if (!follow) {
422
- log(`No logs found for filter: {${filterOptions}}`);
423
- }
424
- } else {
425
- if (!follow && !filter.afterLog) {
426
- log('Logs found: \n');
427
- }
428
- logs.forEach(unencryptedLog => log(unencryptedLog.toHumanReadable()));
429
- // Set the continuation parameter for the following requests
430
- filter.afterLog = logs[logs.length - 1].id;
431
- }
432
- return response.maxLogsHit;
433
- };
434
-
435
- if (follow) {
436
- log('Fetching logs...');
437
- while (true) {
438
- const maxLogsHit = await fetchLogs();
439
- if (!maxLogsHit) {
440
- await sleep(1000);
441
- }
442
- }
443
- } else {
444
- while (await fetchLogs()) {
445
- // Keep fetching logs until we reach the end.
446
- }
447
- }
267
+ const { getLogs } = await import('./cmds/get_logs.js');
268
+ await getLogs(txHash, fromBlock, toBlock, afterLog, contractAddress, selector, rpcUrl, follow, debugLogger, log);
448
269
  });
449
270
 
450
271
  program
@@ -459,9 +280,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
459
280
  )
460
281
  .addOption(pxeOption)
461
282
  .action(async ({ address, publicKey, partialAddress, rpcUrl }) => {
462
- const client = await createCompatibleClient(rpcUrl, debugLogger);
463
- await client.registerRecipient(CompleteAddress.create(address, publicKey, partialAddress));
464
- log(`\nRegistered details for account with address: ${address}\n`);
283
+ const { registerRecipient } = await import('./cmds/register_recipient.js');
284
+ await registerRecipient(address, publicKey, partialAddress, rpcUrl, debugLogger, log);
465
285
  });
466
286
 
467
287
  program
@@ -469,16 +289,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
469
289
  .description('Gets all the Aztec accounts stored in the PXE.')
470
290
  .addOption(pxeOption)
471
291
  .action(async (options: any) => {
472
- const client = await createCompatibleClient(options.rpcUrl, debugLogger);
473
- const accounts = await client.getRegisteredAccounts();
474
- if (!accounts.length) {
475
- log('No accounts found.');
476
- } else {
477
- log(`Accounts found: \n`);
478
- for (const account of accounts) {
479
- log(account.toReadableString());
480
- }
481
- }
292
+ const { getAccounts } = await import('./cmds/get_accounts.js');
293
+ await getAccounts(options.rpcUrl, debugLogger, log);
482
294
  });
483
295
 
484
296
  program
@@ -487,14 +299,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
487
299
  .argument('<address>', 'The Aztec address to get account for', parseAztecAddress)
488
300
  .addOption(pxeOption)
489
301
  .action(async (address, options) => {
490
- const client = await createCompatibleClient(options.rpcUrl, debugLogger);
491
- const account = await client.getRegisteredAccount(address);
492
-
493
- if (!account) {
494
- log(`Unknown account ${address.toString()}`);
495
- } else {
496
- log(account.toReadableString());
497
- }
302
+ const { getAccount } = await import('./cmds/get_account.js');
303
+ await getAccount(address, options.rpcUrl, debugLogger, log);
498
304
  });
499
305
 
500
306
  program
@@ -502,16 +308,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
502
308
  .description('Gets all the recipients stored in the PXE.')
503
309
  .addOption(pxeOption)
504
310
  .action(async (options: any) => {
505
- const client = await createCompatibleClient(options.rpcUrl, debugLogger);
506
- const recipients = await client.getRecipients();
507
- if (!recipients.length) {
508
- log('No recipients found.');
509
- } else {
510
- log(`Recipients found: \n`);
511
- for (const recipient of recipients) {
512
- log(recipient.toReadableString());
513
- }
514
- }
311
+ const { getRecipients } = await import('./cmds/get_recipients.js');
312
+ await getRecipients(options.rpcUrl, debugLogger, log);
515
313
  });
516
314
 
517
315
  program
@@ -520,14 +318,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
520
318
  .argument('<address>', 'The Aztec address to get recipient for', parseAztecAddress)
521
319
  .addOption(pxeOption)
522
320
  .action(async (address, options) => {
523
- const client = await createCompatibleClient(options.rpcUrl, debugLogger);
524
- const recipient = await client.getRecipient(address);
525
-
526
- if (!recipient) {
527
- log(`Unknown recipient ${address.toString()}`);
528
- } else {
529
- log(recipient.toReadableString());
530
- }
321
+ const { getRecipient } = await import('./cmds/get_recipient.js');
322
+ await getRecipient(address, options.rpcUrl, debugLogger, log);
531
323
  });
532
324
 
533
325
  program
@@ -544,31 +336,18 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
544
336
  .addOption(pxeOption)
545
337
  .option('--no-wait', 'Print transaction hash without waiting for it to be mined')
546
338
  .action(async (functionName, options) => {
547
- const { functionArgs, contractArtifact } = await prepTx(
548
- options.contractArtifact,
339
+ const { send } = await import('./cmds/send.js');
340
+ await send(
549
341
  functionName,
550
342
  options.args,
343
+ options.contractArtifact,
344
+ options.contractAddress,
345
+ options.privateKey,
346
+ options.rpcUrl,
347
+ !options.noWait,
348
+ debugLogger,
551
349
  log,
552
350
  );
553
- const { contractAddress, privateKey } = options;
554
-
555
- const client = await createCompatibleClient(options.rpcUrl, debugLogger);
556
- const wallet = await getSchnorrAccount(client, privateKey, privateKey, accountCreationSalt).getWallet();
557
- const contract = await Contract.at(contractAddress, contractArtifact, wallet);
558
- const tx = contract.methods[functionName](...functionArgs).send();
559
- log(`\nTransaction hash: ${(await tx.getTxHash()).toString()}`);
560
- if (options.wait) {
561
- await tx.wait();
562
-
563
- log('Transaction has been mined');
564
-
565
- const receipt = await tx.getReceipt();
566
- log(`Status: ${receipt.status}\n`);
567
- log(`Block number: ${receipt.blockNumber}`);
568
- log(`Block hash: ${receipt.blockHash?.toString('hex')}`);
569
- } else {
570
- log('Transaction pending. Check status with get-tx-receipt');
571
- }
572
351
  });
573
352
 
574
353
  program
@@ -586,23 +365,17 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
586
365
  .option('-f, --from <string>', 'Aztec address of the caller. If empty, will use the first account from RPC.')
587
366
  .addOption(pxeOption)
588
367
  .action(async (functionName, options) => {
589
- const { functionArgs, contractArtifact } = await prepTx(
590
- options.contractArtifact,
368
+ const { call } = await import('./cmds/call.js');
369
+ await call(
591
370
  functionName,
592
371
  options.args,
372
+ options.contractArtifact,
373
+ options.contractAddress,
374
+ options.from,
375
+ options.rpcUrl,
376
+ debugLogger,
593
377
  log,
594
378
  );
595
-
596
- const fnArtifact = getFunctionArtifact(contractArtifact, functionName);
597
- if (fnArtifact.parameters.length !== options.args.length) {
598
- throw Error(
599
- `Invalid number of args passed. Expected ${fnArtifact.parameters.length}; Received: ${options.args.length}`,
600
- );
601
- }
602
- const client = await createCompatibleClient(options.rpcUrl, debugLogger);
603
- const from = await getTxSender(client, options.from);
604
- const result = await client.viewTx(functionName, functionArgs, options.contractAddress, from);
605
- log(format('\nView result: ', result, '\n'));
606
379
  });
607
380
 
608
381
  program
@@ -615,10 +388,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
615
388
  .requiredOption('-n, --note [note...]', 'The members of a Note serialized as hex strings.', [])
616
389
  .addOption(pxeOption)
617
390
  .action(async (address, contractAddress, storageSlot, txHash, options) => {
618
- const note = new Note(parseFields(options.note));
619
- const extendedNote = new ExtendedNote(note, address, contractAddress, storageSlot, txHash);
620
- const client = await createCompatibleClient(options.rpcUrl, debugLogger);
621
- await client.addNote(extendedNote);
391
+ const { addNote } = await import('./cmds/add_note.js');
392
+ await addNote(address, contractAddress, storageSlot, txHash, options.note, options.rpcUrl, debugLogger);
622
393
  });
623
394
 
624
395
  // Helper for users to decode hex strings into structs if needed.
@@ -632,17 +403,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
632
403
  )
633
404
  .requiredOption('-p, --parameter <parameterName>', 'The name of the struct parameter to decode into')
634
405
  .action(async (encodedString, options) => {
635
- const contractArtifact = await getContractArtifact(options.contractArtifact, log);
636
- const parameterAbitype = contractArtifact.functions
637
- .map(({ parameters }) => parameters)
638
- .flat()
639
- .find(({ name, type }) => name === options.parameter && type.kind === 'struct');
640
- if (!parameterAbitype) {
641
- log(`No struct parameter found with name ${options.parameter}`);
642
- return;
643
- }
644
- const data = parseStructString(encodedString, parameterAbitype.type as StructType);
645
- log(`\nStruct Data: \n${JsonStringify(data, true)}\n`);
406
+ const { parseParameterStruct } = await import('./cmds/parse_parameter_struct.js');
407
+ await parseParameterStruct(encodedString, options.contractArtifact, options.parameter, log);
646
408
  });
647
409
 
648
410
  program
@@ -650,18 +412,16 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
650
412
  .description('Gets the current Aztec L2 block number.')
651
413
  .addOption(pxeOption)
652
414
  .action(async (options: any) => {
653
- const client = await createCompatibleClient(options.rpcUrl, debugLogger);
654
- const num = await client.getBlockNumber();
655
- log(`${num}\n`);
415
+ const { blockNumber } = await import('./cmds/block_number.js');
416
+ await blockNumber(options.rpcUrl, debugLogger, log);
656
417
  });
657
418
 
658
419
  program
659
420
  .command('example-contracts')
660
421
  .description('Lists the example contracts available to deploy from @aztec/noir-contracts')
661
422
  .action(async () => {
662
- const abisList = await getExampleContractArtifacts();
663
- const names = Object.keys(abisList);
664
- names.forEach(name => log(name));
423
+ const { exampleContracts } = await import('./cmds/example_contracts.js');
424
+ await exampleContracts(log);
665
425
  });
666
426
 
667
427
  program
@@ -675,8 +435,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
675
435
  'Local directory to unbox source folder to (relative or absolute), optional - defaults to `<contractName>/`',
676
436
  )
677
437
  .action(async (contractName, localDirectory) => {
678
- const unboxTo: string = localDirectory ? localDirectory : contractName;
679
- await unboxContract(contractName, unboxTo, cliVersion, log);
438
+ const { unbox } = await import('./cmds/unbox.js');
439
+ await unbox(contractName, localDirectory, cliVersion, log);
680
440
  });
681
441
 
682
442
  program
@@ -684,14 +444,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
684
444
  .description('Gets the information of an aztec node at a URL.')
685
445
  .addOption(pxeOption)
686
446
  .action(async options => {
687
- const client = await createCompatibleClient(options.rpcUrl, debugLogger);
688
- const info = await client.getNodeInfo();
689
- log(`\nNode Info:\n`);
690
- log(`Sandbox Version: ${info.sandboxVersion}\n`);
691
- log(`Compatible Nargo Version: ${info.compatibleNargoVersion}\n`);
692
- log(`Chain Id: ${info.chainId}\n`);
693
- log(`Protocol Version: ${info.protocolVersion}\n`);
694
- log(`Rollup Address: ${info.l1ContractAddresses.rollupAddress.toString()}`);
447
+ const { getNodeInfo } = await import('./cmds/get_node_info.js');
448
+ await getNodeInfo(options.rpcUrl, debugLogger, log);
695
449
  });
696
450
 
697
451
  program
@@ -702,30 +456,17 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
702
456
  `A compiled Noir contract's artifact in JSON format or name of a contract artifact exported by @aztec/noir-contracts`,
703
457
  )
704
458
  .action(async (contractArtifactFile: string) => {
705
- const contractArtifact = await getContractArtifact(contractArtifactFile, debugLogger);
706
- const contractFns = contractArtifact.functions.filter(
707
- f => !f.isInternal && f.name !== 'compute_note_hash_and_nullifier',
708
- );
709
- if (contractFns.length === 0) {
710
- log(`No external functions found for contract ${contractArtifact.name}`);
711
- }
712
- for (const fn of contractFns) {
713
- const signatureWithParameterNames = decodeFunctionSignatureWithParameterNames(fn.name, fn.parameters);
714
- const signature = decodeFunctionSignature(fn.name, fn.parameters);
715
- const selector = FunctionSelector.fromSignature(signature);
716
- log(
717
- `${fn.functionType} ${signatureWithParameterNames} \n\tfunction signature: ${signature}\n\tselector: ${selector}`,
718
- );
719
- }
459
+ const { inspectContract } = await import('./cmds/inspect_contract.js');
460
+ await inspectContract(contractArtifactFile, debugLogger, log);
720
461
  });
721
462
 
722
463
  program
723
464
  .command('compute-selector')
724
465
  .description('Given a function signature, it computes a selector')
725
466
  .argument('<functionSignature>', 'Function signature to compute selector for e.g. foo(Field)')
726
- .action((functionSignature: string) => {
727
- const selector = FunctionSelector.fromSignature(functionSignature);
728
- log(`${selector}`);
467
+ .action(async (functionSignature: string) => {
468
+ const { computeSelector } = await import('./cmds/compute_selector.js');
469
+ computeSelector(functionSignature, log);
729
470
  });
730
471
 
731
472
  program
@@ -736,13 +477,11 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
736
477
  .option('--sandbox-version <semver>', 'The sandbox version to update to. Defaults to latest', 'latest')
737
478
  .addOption(pxeOption)
738
479
  .action(async (projectPath: string, options) => {
739
- const { contract } = options;
740
- await update(projectPath, contract, options.rpcUrl, options.sandboxVersion, log, debugLogger);
480
+ const { update } = await import('./update/update.js');
481
+ await update(projectPath, options.contract, options.rpcUrl, options.sandboxVersion, log, debugLogger);
741
482
  });
742
483
 
743
- compileNoir(program, 'compile', log);
744
- generateTypescriptInterface(program, 'generate-typescript', log);
745
- generateNoirInterface(program, 'generate-noir-interface', log);
484
+ addNoirCompilerCommanderActions(program, log);
746
485
 
747
486
  return program;
748
487
  }