@aztec/end-to-end 2.0.0-nightly.20250824 → 2.0.0-nightly.20250826
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.
- package/package.json +35 -35
- package/dest/sample-dapp/connect.d.mts +0 -2
- package/dest/sample-dapp/connect.d.mts.map +0 -1
- package/dest/sample-dapp/connect.js +0 -12
- package/dest/sample-dapp/contracts.d.mts +0 -3
- package/dest/sample-dapp/contracts.d.mts.map +0 -1
- package/dest/sample-dapp/contracts.js +0 -10
- package/dest/sample-dapp/deploy.d.mts +0 -3
- package/dest/sample-dapp/deploy.d.mts.map +0 -1
- package/dest/sample-dapp/deploy.js +0 -39
- package/dest/sample-dapp/index.d.mts +0 -2
- package/dest/sample-dapp/index.d.mts.map +0 -1
- package/dest/sample-dapp/index.js +0 -108
- package/src/sample-dapp/connect.mjs +0 -16
- package/src/sample-dapp/contracts.mjs +0 -14
- package/src/sample-dapp/deploy.mjs +0 -42
- package/src/sample-dapp/index.mjs +0 -131
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/end-to-end",
|
|
3
|
-
"version": "2.0.0-nightly.
|
|
3
|
+
"version": "2.0.0-nightly.20250826",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": "./dest/index.js",
|
|
6
6
|
"inherits": [
|
|
@@ -25,40 +25,40 @@
|
|
|
25
25
|
"formatting": "run -T prettier --check ./src && run -T eslint ./src"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aztec/accounts": "2.0.0-nightly.
|
|
29
|
-
"@aztec/archiver": "2.0.0-nightly.
|
|
30
|
-
"@aztec/aztec": "2.0.0-nightly.
|
|
31
|
-
"@aztec/aztec-node": "2.0.0-nightly.
|
|
32
|
-
"@aztec/aztec.js": "2.0.0-nightly.
|
|
33
|
-
"@aztec/bb-prover": "2.0.0-nightly.
|
|
34
|
-
"@aztec/blob-lib": "2.0.0-nightly.
|
|
35
|
-
"@aztec/blob-sink": "2.0.0-nightly.
|
|
36
|
-
"@aztec/bot": "2.0.0-nightly.
|
|
37
|
-
"@aztec/cli": "2.0.0-nightly.
|
|
38
|
-
"@aztec/constants": "2.0.0-nightly.
|
|
39
|
-
"@aztec/entrypoints": "2.0.0-nightly.
|
|
40
|
-
"@aztec/epoch-cache": "2.0.0-nightly.
|
|
41
|
-
"@aztec/ethereum": "2.0.0-nightly.
|
|
42
|
-
"@aztec/foundation": "2.0.0-nightly.
|
|
43
|
-
"@aztec/kv-store": "2.0.0-nightly.
|
|
44
|
-
"@aztec/l1-artifacts": "2.0.0-nightly.
|
|
45
|
-
"@aztec/merkle-tree": "2.0.0-nightly.
|
|
46
|
-
"@aztec/noir-contracts.js": "2.0.0-nightly.
|
|
47
|
-
"@aztec/noir-noirc_abi": "2.0.0-nightly.
|
|
48
|
-
"@aztec/noir-protocol-circuits-types": "2.0.0-nightly.
|
|
49
|
-
"@aztec/noir-test-contracts.js": "2.0.0-nightly.
|
|
50
|
-
"@aztec/p2p": "2.0.0-nightly.
|
|
51
|
-
"@aztec/protocol-contracts": "2.0.0-nightly.
|
|
52
|
-
"@aztec/prover-client": "2.0.0-nightly.
|
|
53
|
-
"@aztec/prover-node": "2.0.0-nightly.
|
|
54
|
-
"@aztec/pxe": "2.0.0-nightly.
|
|
55
|
-
"@aztec/sequencer-client": "2.0.0-nightly.
|
|
56
|
-
"@aztec/simulator": "2.0.0-nightly.
|
|
57
|
-
"@aztec/slasher": "2.0.0-nightly.
|
|
58
|
-
"@aztec/stdlib": "2.0.0-nightly.
|
|
59
|
-
"@aztec/telemetry-client": "2.0.0-nightly.
|
|
60
|
-
"@aztec/validator-client": "2.0.0-nightly.
|
|
61
|
-
"@aztec/world-state": "2.0.0-nightly.
|
|
28
|
+
"@aztec/accounts": "2.0.0-nightly.20250826",
|
|
29
|
+
"@aztec/archiver": "2.0.0-nightly.20250826",
|
|
30
|
+
"@aztec/aztec": "2.0.0-nightly.20250826",
|
|
31
|
+
"@aztec/aztec-node": "2.0.0-nightly.20250826",
|
|
32
|
+
"@aztec/aztec.js": "2.0.0-nightly.20250826",
|
|
33
|
+
"@aztec/bb-prover": "2.0.0-nightly.20250826",
|
|
34
|
+
"@aztec/blob-lib": "2.0.0-nightly.20250826",
|
|
35
|
+
"@aztec/blob-sink": "2.0.0-nightly.20250826",
|
|
36
|
+
"@aztec/bot": "2.0.0-nightly.20250826",
|
|
37
|
+
"@aztec/cli": "2.0.0-nightly.20250826",
|
|
38
|
+
"@aztec/constants": "2.0.0-nightly.20250826",
|
|
39
|
+
"@aztec/entrypoints": "2.0.0-nightly.20250826",
|
|
40
|
+
"@aztec/epoch-cache": "2.0.0-nightly.20250826",
|
|
41
|
+
"@aztec/ethereum": "2.0.0-nightly.20250826",
|
|
42
|
+
"@aztec/foundation": "2.0.0-nightly.20250826",
|
|
43
|
+
"@aztec/kv-store": "2.0.0-nightly.20250826",
|
|
44
|
+
"@aztec/l1-artifacts": "2.0.0-nightly.20250826",
|
|
45
|
+
"@aztec/merkle-tree": "2.0.0-nightly.20250826",
|
|
46
|
+
"@aztec/noir-contracts.js": "2.0.0-nightly.20250826",
|
|
47
|
+
"@aztec/noir-noirc_abi": "2.0.0-nightly.20250826",
|
|
48
|
+
"@aztec/noir-protocol-circuits-types": "2.0.0-nightly.20250826",
|
|
49
|
+
"@aztec/noir-test-contracts.js": "2.0.0-nightly.20250826",
|
|
50
|
+
"@aztec/p2p": "2.0.0-nightly.20250826",
|
|
51
|
+
"@aztec/protocol-contracts": "2.0.0-nightly.20250826",
|
|
52
|
+
"@aztec/prover-client": "2.0.0-nightly.20250826",
|
|
53
|
+
"@aztec/prover-node": "2.0.0-nightly.20250826",
|
|
54
|
+
"@aztec/pxe": "2.0.0-nightly.20250826",
|
|
55
|
+
"@aztec/sequencer-client": "2.0.0-nightly.20250826",
|
|
56
|
+
"@aztec/simulator": "2.0.0-nightly.20250826",
|
|
57
|
+
"@aztec/slasher": "2.0.0-nightly.20250826",
|
|
58
|
+
"@aztec/stdlib": "2.0.0-nightly.20250826",
|
|
59
|
+
"@aztec/telemetry-client": "2.0.0-nightly.20250826",
|
|
60
|
+
"@aztec/validator-client": "2.0.0-nightly.20250826",
|
|
61
|
+
"@aztec/world-state": "2.0.0-nightly.20250826",
|
|
62
62
|
"@iarna/toml": "^2.2.5",
|
|
63
63
|
"@jest/globals": "^30.0.0",
|
|
64
64
|
"@noble/curves": "=1.0.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connect.d.mts","sourceRoot":"","sources":["../../src/sample-dapp/connect.mjs"],"names":[],"mappings":""}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// docs:start:all
|
|
2
|
-
import { createPXEClient } from '@aztec/aztec.js';
|
|
3
|
-
const { PXE_URL = 'http://localhost:8080' } = process.env;
|
|
4
|
-
async function main() {
|
|
5
|
-
const pxe = createPXEClient(PXE_URL);
|
|
6
|
-
const { l1ChainId } = await pxe.getNodeInfo();
|
|
7
|
-
console.log(`Connected to chain ${l1ChainId}`);
|
|
8
|
-
}
|
|
9
|
-
main().catch((err)=>{
|
|
10
|
-
console.error(`Error in app: ${err}`);
|
|
11
|
-
process.exit(1);
|
|
12
|
-
}); // docs:end:all
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contracts.d.mts","sourceRoot":"","sources":["../../src/sample-dapp/contracts.mjs"],"names":[],"mappings":"AASA,yDAGC;yBAZsC,iBAAiB"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { AztecAddress, Contract } from '@aztec/aztec.js';
|
|
2
|
-
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
3
|
-
import { readFileSync } from 'fs';
|
|
4
|
-
// This syntax is helpful for the referencing tutorial
|
|
5
|
-
const TokenContractArtifact = TokenContract.artifact;
|
|
6
|
-
// docs:start:get-tokens
|
|
7
|
-
export function getToken(wallet) {
|
|
8
|
-
const addresses = JSON.parse(readFileSync('addresses.json'));
|
|
9
|
-
return Contract.at(AztecAddress.fromString(addresses.token), TokenContractArtifact, wallet);
|
|
10
|
-
} // docs:end:get-tokens
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.mts","sourceRoot":"","sources":["../../src/sample-dapp/deploy.mjs"],"names":[],"mappings":";AAeA,uCAeC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// docs:start:deploy-imports
|
|
2
|
-
import { getInitialTestAccountsWallets } from '@aztec/accounts/testing';
|
|
3
|
-
import { Contract, createPXEClient, waitForPXE } from '@aztec/aztec.js';
|
|
4
|
-
// docs:end:deploy-imports
|
|
5
|
-
// docs:start:import_artifact
|
|
6
|
-
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
|
|
7
|
-
// docs:end:import_artifact
|
|
8
|
-
import { writeFileSync } from 'fs';
|
|
9
|
-
import { fileURLToPath } from 'url';
|
|
10
|
-
// docs:start:dapp-deploy
|
|
11
|
-
const { PXE_URL = 'http://localhost:8080' } = process.env;
|
|
12
|
-
async function main() {
|
|
13
|
-
const pxe = createPXEClient(PXE_URL);
|
|
14
|
-
await waitForPXE(pxe);
|
|
15
|
-
const [ownerWallet] = await getInitialTestAccountsWallets(pxe);
|
|
16
|
-
const ownerAddress = ownerWallet.getAddress();
|
|
17
|
-
const token = await Contract.deploy(ownerWallet, TokenContractArtifact, [
|
|
18
|
-
ownerAddress,
|
|
19
|
-
'TokenName',
|
|
20
|
-
'TKN',
|
|
21
|
-
18
|
|
22
|
-
]).send({
|
|
23
|
-
from: ownerAddress
|
|
24
|
-
}).deployed();
|
|
25
|
-
console.log(`Token deployed at ${token.address.toString()}`);
|
|
26
|
-
const addresses = {
|
|
27
|
-
token: token.address.toString()
|
|
28
|
-
};
|
|
29
|
-
writeFileSync('addresses.json', JSON.stringify(addresses, null, 2));
|
|
30
|
-
}
|
|
31
|
-
// docs:end:dapp-deploy
|
|
32
|
-
// Execute main only if run directly
|
|
33
|
-
if (process.argv[1].replace(/\/index\.m?js$/, '') === fileURLToPath(import.meta.url).replace(/\/index\.m?js$/, '')) {
|
|
34
|
-
main().catch((err)=>{
|
|
35
|
-
console.error(`Error in deployment script: ${err}`);
|
|
36
|
-
process.exit(1);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
export { main as deploy };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/sample-dapp/index.mjs"],"names":[],"mappings":"AAwGA,sCAcC"}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
// docs:start:imports
|
|
2
|
-
import { getInitialTestAccountsWallets } from '@aztec/accounts/testing';
|
|
3
|
-
import { createPXEClient, waitForPXE } from '@aztec/aztec.js';
|
|
4
|
-
import { fileURLToPath } from '@aztec/foundation/url';
|
|
5
|
-
import { getToken } from './contracts.mjs';
|
|
6
|
-
// docs:end:imports
|
|
7
|
-
const { PXE_URL = 'http://localhost:8080' } = process.env;
|
|
8
|
-
// docs:start:showAccounts
|
|
9
|
-
async function showAccounts(pxe) {
|
|
10
|
-
const accounts = await pxe.getRegisteredAccounts();
|
|
11
|
-
console.log(`User accounts:\n${accounts.map((a)=>a.address).join('\n')}`);
|
|
12
|
-
}
|
|
13
|
-
// docs:end:showAccounts
|
|
14
|
-
// docs:start:showPrivateBalances
|
|
15
|
-
async function showPrivateBalances(pxe) {
|
|
16
|
-
const [owner] = await getInitialTestAccountsWallets(pxe);
|
|
17
|
-
const token = await getToken(owner);
|
|
18
|
-
const accounts = await pxe.getRegisteredAccounts();
|
|
19
|
-
for (const account of accounts){
|
|
20
|
-
// highlight-next-line:showPrivateBalances
|
|
21
|
-
const balance = await token.methods.balance_of_private(account.address).simulate({
|
|
22
|
-
from: account.address
|
|
23
|
-
});
|
|
24
|
-
console.log(`Balance of ${account.address}: ${balance}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
// docs:end:showPrivateBalances
|
|
28
|
-
// docs:start:mintPrivateFunds
|
|
29
|
-
async function mintPrivateFunds(pxe) {
|
|
30
|
-
const [ownerWallet] = await getInitialTestAccountsWallets(pxe);
|
|
31
|
-
const token = await getToken(ownerWallet);
|
|
32
|
-
await showPrivateBalances(pxe);
|
|
33
|
-
// We mint tokens to the owner
|
|
34
|
-
const mintAmount = 20n;
|
|
35
|
-
await token.methods.mint_to_private(ownerWallet.getAddress(), mintAmount).send({
|
|
36
|
-
from: ownerWallet.getAddress()
|
|
37
|
-
}).wait();
|
|
38
|
-
await showPrivateBalances(pxe);
|
|
39
|
-
}
|
|
40
|
-
// docs:end:mintPrivateFunds
|
|
41
|
-
// docs:start:transferPrivateFunds
|
|
42
|
-
async function transferPrivateFunds(pxe) {
|
|
43
|
-
const [owner, recipient] = await getInitialTestAccountsWallets(pxe);
|
|
44
|
-
const token = await getToken(owner);
|
|
45
|
-
await showPrivateBalances(pxe);
|
|
46
|
-
console.log(`Sending transaction, awaiting transaction to be mined`);
|
|
47
|
-
const receipt = await token.methods.transfer(recipient.getAddress(), 1).send({
|
|
48
|
-
from: owner.getAddress()
|
|
49
|
-
}).wait();
|
|
50
|
-
console.log(`Transaction ${receipt.txHash} has been mined on block ${receipt.blockNumber}`);
|
|
51
|
-
await showPrivateBalances(pxe);
|
|
52
|
-
}
|
|
53
|
-
// docs:end:transferPrivateFunds
|
|
54
|
-
// docs:start:showPublicBalances
|
|
55
|
-
async function showPublicBalances(pxe) {
|
|
56
|
-
const [owner] = await getInitialTestAccountsWallets(pxe);
|
|
57
|
-
const token = await getToken(owner);
|
|
58
|
-
const accounts = await pxe.getRegisteredAccounts();
|
|
59
|
-
for (const account of accounts){
|
|
60
|
-
// highlight-next-line:showPublicBalances
|
|
61
|
-
const balance = await token.methods.balance_of_public(account.address).simulate({
|
|
62
|
-
from: account.address
|
|
63
|
-
});
|
|
64
|
-
console.log(`Balance of ${account.address}: ${balance}`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
// docs:end:showPublicBalances
|
|
68
|
-
// docs:start:mintPublicFunds
|
|
69
|
-
async function mintPublicFunds(pxe) {
|
|
70
|
-
const [owner] = await getInitialTestAccountsWallets(pxe);
|
|
71
|
-
const token = await getToken(owner);
|
|
72
|
-
await showPublicBalances(pxe);
|
|
73
|
-
console.log(`Sending transaction, awaiting transaction to be mined`);
|
|
74
|
-
const receipt = await token.methods.mint_to_public(owner.getAddress(), 100).send({
|
|
75
|
-
from: owner.getAddress()
|
|
76
|
-
}).wait();
|
|
77
|
-
console.log(`Transaction ${receipt.txHash} has been mined on block ${receipt.blockNumber}`);
|
|
78
|
-
await showPublicBalances(pxe);
|
|
79
|
-
// docs:start:showLogs
|
|
80
|
-
const blockNumber = await pxe.getBlockNumber();
|
|
81
|
-
const logs = (await pxe.getPublicLogs({
|
|
82
|
-
fromBlock: blockNumber - 1
|
|
83
|
-
})).logs;
|
|
84
|
-
const textLogs = logs.map((extendedLog)=>extendedLog.toHumanReadable().slice(0, 200));
|
|
85
|
-
for (const log of textLogs){
|
|
86
|
-
console.log(`Log emitted: ${log}`);
|
|
87
|
-
}
|
|
88
|
-
// docs:end:showLogs
|
|
89
|
-
}
|
|
90
|
-
// docs:end:mintPublicFunds
|
|
91
|
-
async function main() {
|
|
92
|
-
const pxe = createPXEClient(PXE_URL);
|
|
93
|
-
await waitForPXE(pxe);
|
|
94
|
-
const { l1ChainId } = await pxe.getNodeInfo();
|
|
95
|
-
console.log(`Connected to chain ${l1ChainId}`);
|
|
96
|
-
await showAccounts(pxe);
|
|
97
|
-
await mintPrivateFunds(pxe);
|
|
98
|
-
await transferPrivateFunds(pxe);
|
|
99
|
-
await mintPublicFunds(pxe);
|
|
100
|
-
}
|
|
101
|
-
// Execute main only if run directly
|
|
102
|
-
if (process.argv[1].replace(/\/index\.m?js$/, '') === fileURLToPath(import.meta.url).replace(/\/index\.m?js$/, '')) {
|
|
103
|
-
main().then(()=>process.exit(0)).catch((err)=>{
|
|
104
|
-
console.error(`Error in app: ${err}`);
|
|
105
|
-
process.exit(1);
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
export { main };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// docs:start:all
|
|
2
|
-
import { createPXEClient } from '@aztec/aztec.js';
|
|
3
|
-
|
|
4
|
-
const { PXE_URL = 'http://localhost:8080' } = process.env;
|
|
5
|
-
|
|
6
|
-
async function main() {
|
|
7
|
-
const pxe = createPXEClient(PXE_URL);
|
|
8
|
-
const { l1ChainId } = await pxe.getNodeInfo();
|
|
9
|
-
console.log(`Connected to chain ${l1ChainId}`);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
main().catch(err => {
|
|
13
|
-
console.error(`Error in app: ${err}`);
|
|
14
|
-
process.exit(1);
|
|
15
|
-
});
|
|
16
|
-
// docs:end:all
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AztecAddress, Contract } from '@aztec/aztec.js';
|
|
2
|
-
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
3
|
-
|
|
4
|
-
import { readFileSync } from 'fs';
|
|
5
|
-
|
|
6
|
-
// This syntax is helpful for the referencing tutorial
|
|
7
|
-
const TokenContractArtifact = TokenContract.artifact;
|
|
8
|
-
|
|
9
|
-
// docs:start:get-tokens
|
|
10
|
-
export function getToken(wallet) {
|
|
11
|
-
const addresses = JSON.parse(readFileSync('addresses.json'));
|
|
12
|
-
return Contract.at(AztecAddress.fromString(addresses.token), TokenContractArtifact, wallet);
|
|
13
|
-
}
|
|
14
|
-
// docs:end:get-tokens
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// docs:start:deploy-imports
|
|
2
|
-
import { getInitialTestAccountsWallets } from '@aztec/accounts/testing';
|
|
3
|
-
import { Contract, createPXEClient, waitForPXE } from '@aztec/aztec.js';
|
|
4
|
-
// docs:end:deploy-imports
|
|
5
|
-
// docs:start:import_artifact
|
|
6
|
-
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
|
|
7
|
-
|
|
8
|
-
// docs:end:import_artifact
|
|
9
|
-
|
|
10
|
-
import { writeFileSync } from 'fs';
|
|
11
|
-
import { fileURLToPath } from 'url';
|
|
12
|
-
|
|
13
|
-
// docs:start:dapp-deploy
|
|
14
|
-
const { PXE_URL = 'http://localhost:8080' } = process.env;
|
|
15
|
-
|
|
16
|
-
async function main() {
|
|
17
|
-
const pxe = createPXEClient(PXE_URL);
|
|
18
|
-
await waitForPXE(pxe);
|
|
19
|
-
|
|
20
|
-
const [ownerWallet] = await getInitialTestAccountsWallets(pxe);
|
|
21
|
-
const ownerAddress = ownerWallet.getAddress();
|
|
22
|
-
|
|
23
|
-
const token = await Contract.deploy(ownerWallet, TokenContractArtifact, [ownerAddress, 'TokenName', 'TKN', 18])
|
|
24
|
-
.send({ from: ownerAddress })
|
|
25
|
-
.deployed();
|
|
26
|
-
|
|
27
|
-
console.log(`Token deployed at ${token.address.toString()}`);
|
|
28
|
-
|
|
29
|
-
const addresses = { token: token.address.toString() };
|
|
30
|
-
writeFileSync('addresses.json', JSON.stringify(addresses, null, 2));
|
|
31
|
-
}
|
|
32
|
-
// docs:end:dapp-deploy
|
|
33
|
-
|
|
34
|
-
// Execute main only if run directly
|
|
35
|
-
if (process.argv[1].replace(/\/index\.m?js$/, '') === fileURLToPath(import.meta.url).replace(/\/index\.m?js$/, '')) {
|
|
36
|
-
main().catch(err => {
|
|
37
|
-
console.error(`Error in deployment script: ${err}`);
|
|
38
|
-
process.exit(1);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { main as deploy };
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
// docs:start:imports
|
|
2
|
-
import { getInitialTestAccountsWallets } from '@aztec/accounts/testing';
|
|
3
|
-
import { createPXEClient, waitForPXE } from '@aztec/aztec.js';
|
|
4
|
-
import { fileURLToPath } from '@aztec/foundation/url';
|
|
5
|
-
|
|
6
|
-
import { getToken } from './contracts.mjs';
|
|
7
|
-
|
|
8
|
-
// docs:end:imports
|
|
9
|
-
|
|
10
|
-
const { PXE_URL = 'http://localhost:8080' } = process.env;
|
|
11
|
-
|
|
12
|
-
// docs:start:showAccounts
|
|
13
|
-
async function showAccounts(pxe) {
|
|
14
|
-
const accounts = await pxe.getRegisteredAccounts();
|
|
15
|
-
console.log(`User accounts:\n${accounts.map(a => a.address).join('\n')}`);
|
|
16
|
-
}
|
|
17
|
-
// docs:end:showAccounts
|
|
18
|
-
|
|
19
|
-
// docs:start:showPrivateBalances
|
|
20
|
-
async function showPrivateBalances(pxe) {
|
|
21
|
-
const [owner] = await getInitialTestAccountsWallets(pxe);
|
|
22
|
-
const token = await getToken(owner);
|
|
23
|
-
|
|
24
|
-
const accounts = await pxe.getRegisteredAccounts();
|
|
25
|
-
|
|
26
|
-
for (const account of accounts) {
|
|
27
|
-
// highlight-next-line:showPrivateBalances
|
|
28
|
-
const balance = await token.methods.balance_of_private(account.address).simulate({ from: account.address });
|
|
29
|
-
console.log(`Balance of ${account.address}: ${balance}`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
// docs:end:showPrivateBalances
|
|
33
|
-
|
|
34
|
-
// docs:start:mintPrivateFunds
|
|
35
|
-
async function mintPrivateFunds(pxe) {
|
|
36
|
-
const [ownerWallet] = await getInitialTestAccountsWallets(pxe);
|
|
37
|
-
const token = await getToken(ownerWallet);
|
|
38
|
-
|
|
39
|
-
await showPrivateBalances(pxe);
|
|
40
|
-
|
|
41
|
-
// We mint tokens to the owner
|
|
42
|
-
const mintAmount = 20n;
|
|
43
|
-
await token.methods
|
|
44
|
-
.mint_to_private(ownerWallet.getAddress(), mintAmount)
|
|
45
|
-
.send({ from: ownerWallet.getAddress() })
|
|
46
|
-
.wait();
|
|
47
|
-
|
|
48
|
-
await showPrivateBalances(pxe);
|
|
49
|
-
}
|
|
50
|
-
// docs:end:mintPrivateFunds
|
|
51
|
-
|
|
52
|
-
// docs:start:transferPrivateFunds
|
|
53
|
-
async function transferPrivateFunds(pxe) {
|
|
54
|
-
const [owner, recipient] = await getInitialTestAccountsWallets(pxe);
|
|
55
|
-
const token = await getToken(owner);
|
|
56
|
-
|
|
57
|
-
await showPrivateBalances(pxe);
|
|
58
|
-
console.log(`Sending transaction, awaiting transaction to be mined`);
|
|
59
|
-
const receipt = await token.methods.transfer(recipient.getAddress(), 1).send({ from: owner.getAddress() }).wait();
|
|
60
|
-
|
|
61
|
-
console.log(`Transaction ${receipt.txHash} has been mined on block ${receipt.blockNumber}`);
|
|
62
|
-
await showPrivateBalances(pxe);
|
|
63
|
-
}
|
|
64
|
-
// docs:end:transferPrivateFunds
|
|
65
|
-
|
|
66
|
-
// docs:start:showPublicBalances
|
|
67
|
-
async function showPublicBalances(pxe) {
|
|
68
|
-
const [owner] = await getInitialTestAccountsWallets(pxe);
|
|
69
|
-
const token = await getToken(owner);
|
|
70
|
-
|
|
71
|
-
const accounts = await pxe.getRegisteredAccounts();
|
|
72
|
-
|
|
73
|
-
for (const account of accounts) {
|
|
74
|
-
// highlight-next-line:showPublicBalances
|
|
75
|
-
const balance = await token.methods.balance_of_public(account.address).simulate({ from: account.address });
|
|
76
|
-
console.log(`Balance of ${account.address}: ${balance}`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
// docs:end:showPublicBalances
|
|
80
|
-
|
|
81
|
-
// docs:start:mintPublicFunds
|
|
82
|
-
async function mintPublicFunds(pxe) {
|
|
83
|
-
const [owner] = await getInitialTestAccountsWallets(pxe);
|
|
84
|
-
const token = await getToken(owner);
|
|
85
|
-
|
|
86
|
-
await showPublicBalances(pxe);
|
|
87
|
-
|
|
88
|
-
console.log(`Sending transaction, awaiting transaction to be mined`);
|
|
89
|
-
const receipt = await token.methods.mint_to_public(owner.getAddress(), 100).send({ from: owner.getAddress() }).wait();
|
|
90
|
-
console.log(`Transaction ${receipt.txHash} has been mined on block ${receipt.blockNumber}`);
|
|
91
|
-
|
|
92
|
-
await showPublicBalances(pxe);
|
|
93
|
-
|
|
94
|
-
// docs:start:showLogs
|
|
95
|
-
const blockNumber = await pxe.getBlockNumber();
|
|
96
|
-
const logs = (await pxe.getPublicLogs({ fromBlock: blockNumber - 1 })).logs;
|
|
97
|
-
const textLogs = logs.map(extendedLog => extendedLog.toHumanReadable().slice(0, 200));
|
|
98
|
-
for (const log of textLogs) {
|
|
99
|
-
console.log(`Log emitted: ${log}`);
|
|
100
|
-
}
|
|
101
|
-
// docs:end:showLogs
|
|
102
|
-
}
|
|
103
|
-
// docs:end:mintPublicFunds
|
|
104
|
-
|
|
105
|
-
async function main() {
|
|
106
|
-
const pxe = createPXEClient(PXE_URL);
|
|
107
|
-
await waitForPXE(pxe);
|
|
108
|
-
|
|
109
|
-
const { l1ChainId } = await pxe.getNodeInfo();
|
|
110
|
-
console.log(`Connected to chain ${l1ChainId}`);
|
|
111
|
-
|
|
112
|
-
await showAccounts(pxe);
|
|
113
|
-
|
|
114
|
-
await mintPrivateFunds(pxe);
|
|
115
|
-
|
|
116
|
-
await transferPrivateFunds(pxe);
|
|
117
|
-
|
|
118
|
-
await mintPublicFunds(pxe);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Execute main only if run directly
|
|
122
|
-
if (process.argv[1].replace(/\/index\.m?js$/, '') === fileURLToPath(import.meta.url).replace(/\/index\.m?js$/, '')) {
|
|
123
|
-
main()
|
|
124
|
-
.then(() => process.exit(0))
|
|
125
|
-
.catch(err => {
|
|
126
|
-
console.error(`Error in app: ${err}`);
|
|
127
|
-
process.exit(1);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export { main };
|