-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdeploy-account-contract.ts
More file actions
84 lines (69 loc) · 3 KB
/
deploy-account-contract.ts
File metadata and controls
84 lines (69 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { AztecAddress } from '@aztec/aztec.js/addresses';
import { Fr } from '@aztec/aztec.js/fields';
import { SponsoredFeePaymentMethod } from '@aztec/aztec.js/fee';
import { Contract, DeployMethod, type DeployOptions } from '@aztec/aztec.js/contracts';
import { createAztecNodeClient } from '@aztec/aztec.js/node';
import { deriveKeys } from '@aztec/aztec.js/keys';
import { getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
import { SponsoredFPCContractArtifact } from '@aztec/noir-contracts.js/SponsoredFPC';
import { SPONSORED_FPC_SALT } from '@aztec/constants';
import { PasswordAccountContract } from './password-account-entrypoint';
import { EmbeddedWallet } from '@aztec/wallets/embedded';
import { AccountManager } from '@aztec/aztec.js/wallet';
async function getSponsoredPFCContract() {
const instance = await getContractInstanceFromInstantiationParams(
SponsoredFPCContractArtifact,
{
salt: new Fr(SPONSORED_FPC_SALT),
}
);
return instance;
}
const deployAccountOpts: DeployOptions = {
skipClassPublication: false,
skipInstancePublication: false,
skipInitialization: false,
from: AztecAddress.ZERO,
fee: {
paymentMethod: new SponsoredFeePaymentMethod(
(await getSponsoredPFCContract()).address
),
},
contractAddressSalt: Fr.ONE,
universalDeploy: true,
};
const passwordAccountContract = new PasswordAccountContract(new Fr(123123123123));
const artifact = await passwordAccountContract.getContractArtifact();
const { constructorName, constructorArgs } = await passwordAccountContract.getInitializationFunctionAndArgs();
console.log(constructorName, constructorArgs);
const secretKey = Fr.random();
// const salt = Fr.random();
const { publicKeys } = await deriveKeys(secretKey);
const wallet = await EmbeddedWallet.create(createAztecNodeClient('http://localhost:8080'), { ephemeral: true });
// This doesn't work due to a strange bug in fee payment
// const deployPasswordAccountMethod = new DeployAccountMethod(
// publicKeys,
// wallet,
// artifact,
// address => Contract.at(address, artifact, wallet),
// salt,
// constructorArgs,
// constructorName,
// );
await wallet.registerContract(await getSponsoredPFCContract(), SponsoredFPCContractArtifact);
const accountContractDeployMethod = new DeployMethod(
publicKeys,
wallet,
artifact,
(instance, wallet) => Contract.at(instance.address, artifact, wallet),
constructorArgs,
constructorName,
)
const { estimatedGas, stats } = await accountContractDeployMethod.simulate(deployAccountOpts);
console.log(estimatedGas);
console.log(stats);
const { contract: deployedAccountContract } = await accountContractDeployMethod.send(deployAccountOpts);
console.log('PasswordAccount contract deployed at:', deployedAccountContract.address);
// Create and register an account using the deployed contract
const accountManager = await AccountManager.create(wallet, Fr.random(), passwordAccountContract, Fr.random());
console.log('Account registered at:', accountManager.address.toString());