From 2477f760cd5c652abbb8a231b518478adde5b713 Mon Sep 17 00:00:00 2001 From: Cat McGee Date: Wed, 14 Feb 2024 18:35:21 +0900 Subject: [PATCH 01/12] docs example test file --- .../end-to-end/src/docs_examples.test.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 yarn-project/end-to-end/src/docs_examples.test.ts diff --git a/yarn-project/end-to-end/src/docs_examples.test.ts b/yarn-project/end-to-end/src/docs_examples.test.ts new file mode 100644 index 00000000000..ae2046b53a7 --- /dev/null +++ b/yarn-project/end-to-end/src/docs_examples.test.ts @@ -0,0 +1,39 @@ +import { getSchnorrAccount } from '@aztec/accounts/schnorr'; +import { GrumpkinScalar, createPXEClient } from '@aztec/aztec.js'; +import { Contract } from "@aztec/aztec.js"; +import { TokenContract } from '@aztec/noir-contracts.js/TokenContract'; + +const PXE_URL = process.env.PXE_URL || 'http://localhost:8080'; +const encryptionPrivateKey = GrumpkinScalar.random(); +const signingPrivateKey = GrumpkinScalar.random(); +const pxe = createPXEClient(PXE_URL); + +const wallet = await getSchnorrAccount( + pxe, + encryptionPrivateKey, + signingPrivateKey + ).waitDeploy(); + console.log(`New account deployed at ${wallet.getAddress()}`); + +const deployedContract = await TokenContract.deploy( + wallet, + TokenContract, + 'TokenName', + 'TokenSymbol', + 18) + .send() + .deployed(); +console.log(`New contract deployed at ${deployedContract.address}`) + +const contract = await Contract.at(deployedContract.address, TokenContract, wallet); + +const tx = await contract.methods + .transfer(1, wallet) + .send() + .wait(); +console.log( + `Transferred 1 to ${wallet.getAddress()} on block ${tx.blockNumber}` +); + +const balance = await contract.methods.getBalance(wallet.getAddress()).view(); +console.log(`Account balance is ${balance}`); \ No newline at end of file From a92f80f0561fda4fa0b1e35ba700803a3c2e6523 Mon Sep 17 00:00:00 2001 From: Cat McGee Date: Wed, 14 Feb 2024 18:45:13 +0900 Subject: [PATCH 02/12] call view function --- .../aztecjs/guides/call_view_function.md | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/docs/developers/aztecjs/guides/call_view_function.md b/docs/docs/developers/aztecjs/guides/call_view_function.md index 5fda30f7f2d..873afa94d52 100644 --- a/docs/docs/developers/aztecjs/guides/call_view_function.md +++ b/docs/docs/developers/aztecjs/guides/call_view_function.md @@ -6,10 +6,23 @@ This guide explains how to call a `view` function using [Aztec.js](../main.md). To do this from the CLI, go [here](../../sandbox/references/cli-commands.md#calling-an-unconstrained-view-function). -```typescript -import { Contract } from "@aztec/aztec.js"; +## Relevent imports + +You will need to import this from Aztec.js: + +#include_code import_contract yarn-project/end-to-end/src/docs_examples.test.ts typescript + +## Define contract + +Get a previously deployed contract like this: + +#include_code get_contract yarn-project/end-to-end/src/docs_examples.test.ts typescript + +You can learn how to deploy a contract [here](./deploy_contract.md). + +## Call view function + +Call the `view` function on the contract like this: + +#include_code call_view_function yarn-project/end-to-end/src/docs_examples.test.ts typescript -const contract = await Contract.at(contractAddress, MyContractArtifact, wallet); -const balance = await contract.methods.getBalance(wallet.getAddress()).view(); -console.log(`Account balance is ${balance}`); -``` From 22da8b7bd17f7f6c434a9a62c8ea04f15937f05d Mon Sep 17 00:00:00 2001 From: Cat McGee Date: Wed, 14 Feb 2024 22:11:26 +0900 Subject: [PATCH 03/12] updated docs --- .circleci/config.yml | 14 +++++++- .../aztecjs/guides/call_view_function.md | 10 ++++-- .../aztecjs/guides/create_account.md | 29 ++++++++------- .../aztecjs/guides/deploy_contract.md | 29 +++++++++------ .../aztecjs/guides/send_transaction.md | 35 ++++++++++++------- 5 files changed, 79 insertions(+), 38 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9e8f705c529..a70f56e7dfd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -851,7 +851,6 @@ jobs: - run: name: "Test" command: AVM_ENABLED=1 cond_spot_run_compose end-to-end 4 ./scripts/docker-compose.yml TEST=e2e_avm_simulator.test.ts - pxe: docker: - image: aztecprotocol/alpine-build-image @@ -873,6 +872,17 @@ jobs: - run: name: "Test" command: cond_spot_run_compose end-to-end 4 ./scripts/docker-compose.yml TEST=cli_docs_sandbox.test.ts + + e2e-docs-examples: + docker: + - image: aztecprotocol/alpine-build-image + resource_class: small + steps: + - *checkout + - *setup_env + - run: + name: "Test" + command: AVM_ENABLED=1 cond_spot_run_compose end-to-end 4 ./scripts/docker-compose.yml TEST=docs_examples_test.ts guides-writing-an-account-contract: docker: @@ -1306,6 +1316,7 @@ workflows: - e2e-avm-simulator: *e2e_test - pxe: *e2e_test - cli-docs-sandbox: *e2e_test + - e2e-docs-examples: *e2e_test - guides-writing-an-account-contract: *e2e_test - guides-dapp-testing: *e2e_test - guides-sample-dapp: *e2e_test @@ -1348,6 +1359,7 @@ workflows: - boxes-blank-react - boxes-token - cli-docs-sandbox + - e2e-docs-examples - guides-writing-an-account-contract - guides-dapp-testing - guides-sample-dapp diff --git a/docs/docs/developers/aztecjs/guides/call_view_function.md b/docs/docs/developers/aztecjs/guides/call_view_function.md index 873afa94d52..0e5cbbbd258 100644 --- a/docs/docs/developers/aztecjs/guides/call_view_function.md +++ b/docs/docs/developers/aztecjs/guides/call_view_function.md @@ -6,6 +6,14 @@ This guide explains how to call a `view` function using [Aztec.js](../main.md). To do this from the CLI, go [here](../../sandbox/references/cli-commands.md#calling-an-unconstrained-view-function). +## Prerequisites + +You should have a wallet to act as the caller, and a contract that has been deployed. + +You can learn how to create wallets from [this guide](./create_account.md). + +You can learn how to deploy a contract [here](./deploy_contract.md). + ## Relevent imports You will need to import this from Aztec.js: @@ -18,8 +26,6 @@ Get a previously deployed contract like this: #include_code get_contract yarn-project/end-to-end/src/docs_examples.test.ts typescript -You can learn how to deploy a contract [here](./deploy_contract.md). - ## Call view function Call the `view` function on the contract like this: diff --git a/docs/docs/developers/aztecjs/guides/create_account.md b/docs/docs/developers/aztecjs/guides/create_account.md index bf0913cba44..47157cc6a0f 100644 --- a/docs/docs/developers/aztecjs/guides/create_account.md +++ b/docs/docs/developers/aztecjs/guides/create_account.md @@ -6,16 +6,19 @@ This guide explains how to create a new account using [Aztec.js](../main.md). To do this from the CLI, go [here](../../sandbox/references/cli-commands.md#creating-accounts). -```typescript -import { getSchnorrAccount } from "@aztec/aztec.js"; -import { GrumpkinPrivateKey } from "@aztec/circuit-types"; - -const encryptionPrivateKey = GrumpkinPrivateKey.random(); -const signingPrivateKey = GrumpkinPrivateKey.random(); -const wallet = getSchnorrAccount( - pxe, - encryptionPrivateKey, - signingPrivateKey -).waitDeploy(); -console.log(`New account deployed at ${wallet.getAddress()}`); -``` \ No newline at end of file +## Relevant imports + +You will need to import these libraries: + +#include_code create_account_imports yarn-project/end-to-end/src/docs_examples.test.ts typescript + +## Define arguments needed + +#include_code define_account_vars yarn-project/end-to-end/src/docs_examples.test.ts typescript + +## Create the wallet with these args + +#include_code create_wallet yarn-project/end-to-end/src/docs_examples.test.ts typescript + +Now you have a new wallet in your PXE! To learn how to use this wallet to deploy a contract, read [this guide](./deploy_contract.md). + diff --git a/docs/docs/developers/aztecjs/guides/deploy_contract.md b/docs/docs/developers/aztecjs/guides/deploy_contract.md index 499af437a94..7c01b1c158c 100644 --- a/docs/docs/developers/aztecjs/guides/deploy_contract.md +++ b/docs/docs/developers/aztecjs/guides/deploy_contract.md @@ -6,13 +6,22 @@ This guide explains how to deploy a smart contract using [Aztec.js](../main.md). To do this from the CLI, go [here](../../sandbox/references/cli-commands.md#deploying-a-token-contract). -```typescript -import { Contract } from "@aztec/aztec.js"; - -const contract = await Contract.deploy(wallet, MyContractArtifact, [ - ...constructorArgs, -]) - .send() - .deployed(); -console.log(`Contract deployed at ${contract.address}`); -``` \ No newline at end of file +## Prerequisites + +You should have a wallet to act as the deployer, and a contract artifact ready to be deployed. + +You can learn how to create wallets from [this guide](./create_account.md). + +You can read about contract artifacts [here](../../contracts/compiling_contracts/artifacts.md). + +## Import the contract artifact + +In this guide we are using a Token contract artifact. This comes from the [token contract tutorial](../../tutorials/writing_token_contract.md). + +#include code import_token_contract yarn-project/end-to-end/src/docs_examples.test.ts typescript + +## Deploy contract + +#include code deploy_contract yarn-project/end-to-end/src/docs_examples.test.ts typescript + +This will print the address of your deployed contract. To learn how to send a transaction from Aztec.js read [this guide](./send_transaction.md). You can also call a `view` function from Aztec.js by reading [this guide](./call_view_function.md). \ No newline at end of file diff --git a/docs/docs/developers/aztecjs/guides/send_transaction.md b/docs/docs/developers/aztecjs/guides/send_transaction.md index 8cebd8edd61..0e323c23af5 100644 --- a/docs/docs/developers/aztecjs/guides/send_transaction.md +++ b/docs/docs/developers/aztecjs/guides/send_transaction.md @@ -6,15 +6,26 @@ This guide explains how to send a transaction using [Aztec.js](../main.md). To do this from the CLI, go [here](../../sandbox/references/cli-commands.md#sending-a-transaction). -```typescript -import { Contract } from "@aztec/aztec.js"; - -const contract = await Contract.at(contractAddress, MyContractArtifact, wallet); -const tx = await contract.methods - .transfer(amount, recipientAddress) - .send() - .wait(); -console.log( - `Transferred ${amount} to ${recipientAddress} on block ${tx.blockNumber}` -); -``` \ No newline at end of file +## Prerequisites + +You should have a wallet to act as the transaction sender, and a contract that has been deployed. + +You can learn how to create wallets from [this guide](./create_account.md). + +You can learn how to deploy a contract [here](./deploy_contract.md). + +## Relevant imports + +You will need to import this library: + +#include_code import_contract yarn-project/end-to-end/src/docs_examples.test.ts typescript + +## Define contract + +Get a previously deployed contract like this: + +#include_code get_contract yarn-project/end-to-end/src/docs_examples.test.ts typescript + +## Call method + +#include_code send_transaction yarn-project/end-to-end/src/docs_examples.test.ts typescript From 9f4ff3f0df1e2a4a4ddd4753522369b2f6a15a20 Mon Sep 17 00:00:00 2001 From: Cat McGee Date: Wed, 14 Feb 2024 22:34:07 +0900 Subject: [PATCH 04/12] fix some things --- .../end-to-end/src/docs_examples.test.ts | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/yarn-project/end-to-end/src/docs_examples.test.ts b/yarn-project/end-to-end/src/docs_examples.test.ts index ae2046b53a7..14d65ad9de3 100644 --- a/yarn-project/end-to-end/src/docs_examples.test.ts +++ b/yarn-project/end-to-end/src/docs_examples.test.ts @@ -1,32 +1,47 @@ +// docs:start:create_account_imports import { getSchnorrAccount } from '@aztec/accounts/schnorr'; import { GrumpkinScalar, createPXEClient } from '@aztec/aztec.js'; +// docs:end:create_account_imports +// docs:start:import_contract import { Contract } from "@aztec/aztec.js"; -import { TokenContract } from '@aztec/noir-contracts.js/TokenContract'; +// docs:end:import_contract +// docs:start:import_token_contract +import { TokenContract, TokenContractArtifact } from '@aztec/noir-contracts.js/Token'; +// docs:end:import_token_contract +// docs:start:define_account_vars const PXE_URL = process.env.PXE_URL || 'http://localhost:8080'; const encryptionPrivateKey = GrumpkinScalar.random(); const signingPrivateKey = GrumpkinScalar.random(); const pxe = createPXEClient(PXE_URL); +// docs:end:define_account_vars +// docs:start:create_wallet const wallet = await getSchnorrAccount( - pxe, + pxe, encryptionPrivateKey, signingPrivateKey ).waitDeploy(); console.log(`New account deployed at ${wallet.getAddress()}`); - + // docs:end:create_wallet + +// docs:start:deploy_contract const deployedContract = await TokenContract.deploy( - wallet, - TokenContract, - 'TokenName', - 'TokenSymbol', - 18) + wallet, // wallet instance + wallet.getAddress(), // account + 'TokenName', // constructor arg1 + 'TokenSymbol', // constructor arg2 + 18) // constructor arg3 .send() .deployed(); console.log(`New contract deployed at ${deployedContract.address}`) +// docs:end:deploy_contract -const contract = await Contract.at(deployedContract.address, TokenContract, wallet); +// docs:start:get_contract +const contract = await Contract.at(deployedContract.address, TokenContractArtifact, wallet); +// docs:end:get_contract +// docs:start:send_transaction const tx = await contract.methods .transfer(1, wallet) .send() @@ -34,6 +49,9 @@ const tx = await contract.methods console.log( `Transferred 1 to ${wallet.getAddress()} on block ${tx.blockNumber}` ); +// docs:end:send_transaction +// docs:start:call_view_function const balance = await contract.methods.getBalance(wallet.getAddress()).view(); -console.log(`Account balance is ${balance}`); \ No newline at end of file +console.log(`Account balance is ${balance}`); +// docs:end:call_view_function From 0a419ef5655711f99aea3987984316a290f4ca94 Mon Sep 17 00:00:00 2001 From: Cat McGee Date: Wed, 14 Feb 2024 22:39:35 +0900 Subject: [PATCH 05/12] include_code macro --- docs/docs/developers/aztecjs/guides/deploy_contract.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/developers/aztecjs/guides/deploy_contract.md b/docs/docs/developers/aztecjs/guides/deploy_contract.md index 7c01b1c158c..dcb0511928e 100644 --- a/docs/docs/developers/aztecjs/guides/deploy_contract.md +++ b/docs/docs/developers/aztecjs/guides/deploy_contract.md @@ -18,10 +18,10 @@ You can read about contract artifacts [here](../../contracts/compiling_contracts In this guide we are using a Token contract artifact. This comes from the [token contract tutorial](../../tutorials/writing_token_contract.md). -#include code import_token_contract yarn-project/end-to-end/src/docs_examples.test.ts typescript +#include_code import_token_contract yarn-project/end-to-end/src/docs_examples.test.ts typescript ## Deploy contract -#include code deploy_contract yarn-project/end-to-end/src/docs_examples.test.ts typescript +#include_code deploy_contract yarn-project/end-to-end/src/docs_examples.test.ts typescript This will print the address of your deployed contract. To learn how to send a transaction from Aztec.js read [this guide](./send_transaction.md). You can also call a `view` function from Aztec.js by reading [this guide](./call_view_function.md). \ No newline at end of file From 0d7ecf8904480e9ab610d6d5a6b8406e81b59989 Mon Sep 17 00:00:00 2001 From: Cat McGee Date: Wed, 14 Feb 2024 22:42:09 +0900 Subject: [PATCH 06/12] ci config --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 16b7c929117..365a253a62d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -906,7 +906,7 @@ jobs: name: "Test" command: cond_spot_run_compose end-to-end 4 ./scripts/docker-compose.yml TEST=cli_docs_sandbox.test.ts - e2e-docs-examples: + e2e-docs-examples: docker: - image: aztecprotocol/alpine-build-image resource_class: small From a9f2699cb189b8025dee872efc36d9981ba18330 Mon Sep 17 00:00:00 2001 From: Cat McGee Date: Thu, 15 Feb 2024 18:48:18 +0900 Subject: [PATCH 07/12] yarn format --- .../end-to-end/src/docs_examples.test.ts | 37 ++++++++----------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/yarn-project/end-to-end/src/docs_examples.test.ts b/yarn-project/end-to-end/src/docs_examples.test.ts index 14d65ad9de3..c52a20ca397 100644 --- a/yarn-project/end-to-end/src/docs_examples.test.ts +++ b/yarn-project/end-to-end/src/docs_examples.test.ts @@ -3,10 +3,11 @@ import { getSchnorrAccount } from '@aztec/accounts/schnorr'; import { GrumpkinScalar, createPXEClient } from '@aztec/aztec.js'; // docs:end:create_account_imports // docs:start:import_contract -import { Contract } from "@aztec/aztec.js"; +import { Contract } from '@aztec/aztec.js'; // docs:end:import_contract // docs:start:import_token_contract import { TokenContract, TokenContractArtifact } from '@aztec/noir-contracts.js/Token'; + // docs:end:import_token_contract // docs:start:define_account_vars @@ -17,24 +18,21 @@ const pxe = createPXEClient(PXE_URL); // docs:end:define_account_vars // docs:start:create_wallet -const wallet = await getSchnorrAccount( - pxe, - encryptionPrivateKey, - signingPrivateKey - ).waitDeploy(); - console.log(`New account deployed at ${wallet.getAddress()}`); - // docs:end:create_wallet - +const wallet = await getSchnorrAccount(pxe, encryptionPrivateKey, signingPrivateKey).waitDeploy(); +console.log(`New account deployed at ${wallet.getAddress()}`); +// docs:end:create_wallet + // docs:start:deploy_contract const deployedContract = await TokenContract.deploy( - wallet, // wallet instance - wallet.getAddress(), // account - 'TokenName', // constructor arg1 - 'TokenSymbol', // constructor arg2 - 18) // constructor arg3 + wallet, // wallet instance + wallet.getAddress(), // account + 'TokenName', // constructor arg1 + 'TokenSymbol', // constructor arg2 + 18, +) // constructor arg3 .send() .deployed(); -console.log(`New contract deployed at ${deployedContract.address}`) +console.log(`New contract deployed at ${deployedContract.address}`); // docs:end:deploy_contract // docs:start:get_contract @@ -42,13 +40,8 @@ const contract = await Contract.at(deployedContract.address, TokenContractArtifa // docs:end:get_contract // docs:start:send_transaction -const tx = await contract.methods - .transfer(1, wallet) - .send() - .wait(); -console.log( - `Transferred 1 to ${wallet.getAddress()} on block ${tx.blockNumber}` -); +const tx = await contract.methods.transfer(1, wallet).send().wait(); +console.log(`Transferred 1 to ${wallet.getAddress()} on block ${tx.blockNumber}`); // docs:end:send_transaction // docs:start:call_view_function From 489d10217155ef73d26e5d7ffa086d4fc76c999a Mon Sep 17 00:00:00 2001 From: Cat McGee Date: Thu, 15 Feb 2024 19:37:59 +0900 Subject: [PATCH 08/12] remove console.log --- yarn-project/end-to-end/src/docs_examples.test.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/yarn-project/end-to-end/src/docs_examples.test.ts b/yarn-project/end-to-end/src/docs_examples.test.ts index c52a20ca397..20629fd7fe3 100644 --- a/yarn-project/end-to-end/src/docs_examples.test.ts +++ b/yarn-project/end-to-end/src/docs_examples.test.ts @@ -19,7 +19,6 @@ const pxe = createPXEClient(PXE_URL); // docs:start:create_wallet const wallet = await getSchnorrAccount(pxe, encryptionPrivateKey, signingPrivateKey).waitDeploy(); -console.log(`New account deployed at ${wallet.getAddress()}`); // docs:end:create_wallet // docs:start:deploy_contract @@ -32,7 +31,6 @@ const deployedContract = await TokenContract.deploy( ) // constructor arg3 .send() .deployed(); -console.log(`New contract deployed at ${deployedContract.address}`); // docs:end:deploy_contract // docs:start:get_contract @@ -41,10 +39,8 @@ const contract = await Contract.at(deployedContract.address, TokenContractArtifa // docs:start:send_transaction const tx = await contract.methods.transfer(1, wallet).send().wait(); -console.log(`Transferred 1 to ${wallet.getAddress()} on block ${tx.blockNumber}`); // docs:end:send_transaction // docs:start:call_view_function const balance = await contract.methods.getBalance(wallet.getAddress()).view(); -console.log(`Account balance is ${balance}`); // docs:end:call_view_function From f2e5737047b524fb9fe15e5bfda5f21592517cd5 Mon Sep 17 00:00:00 2001 From: Cat McGee Date: Thu, 15 Feb 2024 19:39:17 +0900 Subject: [PATCH 09/12] remove console.log --- docs/docs/developers/aztecjs/guides/deploy_contract.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/developers/aztecjs/guides/deploy_contract.md b/docs/docs/developers/aztecjs/guides/deploy_contract.md index dcb0511928e..ffa565f33fa 100644 --- a/docs/docs/developers/aztecjs/guides/deploy_contract.md +++ b/docs/docs/developers/aztecjs/guides/deploy_contract.md @@ -24,4 +24,4 @@ In this guide we are using a Token contract artifact. This comes from the [token #include_code deploy_contract yarn-project/end-to-end/src/docs_examples.test.ts typescript -This will print the address of your deployed contract. To learn how to send a transaction from Aztec.js read [this guide](./send_transaction.md). You can also call a `view` function from Aztec.js by reading [this guide](./call_view_function.md). \ No newline at end of file +To learn how to send a transaction from Aztec.js read [this guide](./send_transaction.md). You can also call a `view` function from Aztec.js by reading [this guide](./call_view_function.md). \ No newline at end of file From 76aa6dacb6df9eae900b7fea5fc0b1a474799724 Mon Sep 17 00:00:00 2001 From: Cat McGee Date: Thu, 15 Feb 2024 20:21:40 +0900 Subject: [PATCH 10/12] prettierignore docs examples --- yarn-project/.prettierignore | 1 + .../end-to-end/src/docs_examples.test.ts | 35 ++++++++++++------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/yarn-project/.prettierignore b/yarn-project/.prettierignore index 089b52962fe..21e584bfc3f 100644 --- a/yarn-project/.prettierignore +++ b/yarn-project/.prettierignore @@ -6,3 +6,4 @@ boxes/*/src/artifacts/*.json boxes/*/src/artifacts/*.ts boxes/*/src/contracts/target/*.json *.md +end-to-end/src/docs_examples.test.ts diff --git a/yarn-project/end-to-end/src/docs_examples.test.ts b/yarn-project/end-to-end/src/docs_examples.test.ts index 20629fd7fe3..14d65ad9de3 100644 --- a/yarn-project/end-to-end/src/docs_examples.test.ts +++ b/yarn-project/end-to-end/src/docs_examples.test.ts @@ -3,11 +3,10 @@ import { getSchnorrAccount } from '@aztec/accounts/schnorr'; import { GrumpkinScalar, createPXEClient } from '@aztec/aztec.js'; // docs:end:create_account_imports // docs:start:import_contract -import { Contract } from '@aztec/aztec.js'; +import { Contract } from "@aztec/aztec.js"; // docs:end:import_contract // docs:start:import_token_contract import { TokenContract, TokenContractArtifact } from '@aztec/noir-contracts.js/Token'; - // docs:end:import_token_contract // docs:start:define_account_vars @@ -18,19 +17,24 @@ const pxe = createPXEClient(PXE_URL); // docs:end:define_account_vars // docs:start:create_wallet -const wallet = await getSchnorrAccount(pxe, encryptionPrivateKey, signingPrivateKey).waitDeploy(); -// docs:end:create_wallet - +const wallet = await getSchnorrAccount( + pxe, + encryptionPrivateKey, + signingPrivateKey + ).waitDeploy(); + console.log(`New account deployed at ${wallet.getAddress()}`); + // docs:end:create_wallet + // docs:start:deploy_contract const deployedContract = await TokenContract.deploy( - wallet, // wallet instance - wallet.getAddress(), // account - 'TokenName', // constructor arg1 - 'TokenSymbol', // constructor arg2 - 18, -) // constructor arg3 + wallet, // wallet instance + wallet.getAddress(), // account + 'TokenName', // constructor arg1 + 'TokenSymbol', // constructor arg2 + 18) // constructor arg3 .send() .deployed(); +console.log(`New contract deployed at ${deployedContract.address}`) // docs:end:deploy_contract // docs:start:get_contract @@ -38,9 +42,16 @@ const contract = await Contract.at(deployedContract.address, TokenContractArtifa // docs:end:get_contract // docs:start:send_transaction -const tx = await contract.methods.transfer(1, wallet).send().wait(); +const tx = await contract.methods + .transfer(1, wallet) + .send() + .wait(); +console.log( + `Transferred 1 to ${wallet.getAddress()} on block ${tx.blockNumber}` +); // docs:end:send_transaction // docs:start:call_view_function const balance = await contract.methods.getBalance(wallet.getAddress()).view(); +console.log(`Account balance is ${balance}`); // docs:end:call_view_function From 982063b56831ce180db7650abeac9462d0827261 Mon Sep 17 00:00:00 2001 From: Cat McGee Date: Thu, 15 Feb 2024 20:24:03 +0900 Subject: [PATCH 11/12] remove from unused var error --- .../end-to-end/src/docs_examples.test.ts | 37 +++++++------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/yarn-project/end-to-end/src/docs_examples.test.ts b/yarn-project/end-to-end/src/docs_examples.test.ts index 14d65ad9de3..12d1fb9c0ab 100644 --- a/yarn-project/end-to-end/src/docs_examples.test.ts +++ b/yarn-project/end-to-end/src/docs_examples.test.ts @@ -3,10 +3,11 @@ import { getSchnorrAccount } from '@aztec/accounts/schnorr'; import { GrumpkinScalar, createPXEClient } from '@aztec/aztec.js'; // docs:end:create_account_imports // docs:start:import_contract -import { Contract } from "@aztec/aztec.js"; +import { Contract } from '@aztec/aztec.js'; // docs:end:import_contract // docs:start:import_token_contract import { TokenContract, TokenContractArtifact } from '@aztec/noir-contracts.js/Token'; + // docs:end:import_token_contract // docs:start:define_account_vars @@ -17,24 +18,19 @@ const pxe = createPXEClient(PXE_URL); // docs:end:define_account_vars // docs:start:create_wallet -const wallet = await getSchnorrAccount( - pxe, - encryptionPrivateKey, - signingPrivateKey - ).waitDeploy(); - console.log(`New account deployed at ${wallet.getAddress()}`); - // docs:end:create_wallet - +const wallet = await getSchnorrAccount(pxe, encryptionPrivateKey, signingPrivateKey).waitDeploy(); +// docs:end:create_wallet + // docs:start:deploy_contract const deployedContract = await TokenContract.deploy( - wallet, // wallet instance - wallet.getAddress(), // account - 'TokenName', // constructor arg1 - 'TokenSymbol', // constructor arg2 - 18) // constructor arg3 + wallet, // wallet instance + wallet.getAddress(), // account + 'TokenName', // constructor arg1 + 'TokenSymbol', // constructor arg2 + 18, +) // constructor arg3 .send() .deployed(); -console.log(`New contract deployed at ${deployedContract.address}`) // docs:end:deploy_contract // docs:start:get_contract @@ -42,16 +38,9 @@ const contract = await Contract.at(deployedContract.address, TokenContractArtifa // docs:end:get_contract // docs:start:send_transaction -const tx = await contract.methods - .transfer(1, wallet) - .send() - .wait(); -console.log( - `Transferred 1 to ${wallet.getAddress()} on block ${tx.blockNumber}` -); +const _tx = await contract.methods.transfer(1, wallet).send().wait(); // docs:end:send_transaction // docs:start:call_view_function -const balance = await contract.methods.getBalance(wallet.getAddress()).view(); -console.log(`Account balance is ${balance}`); +const _balance = await contract.methods.getBalance(wallet.getAddress()).view(); // docs:end:call_view_function From e2749ef91f400acc9a50fc2c3647a804ff1b326a Mon Sep 17 00:00:00 2001 From: Cat McGee Date: Thu, 15 Feb 2024 20:29:58 +0900 Subject: [PATCH 12/12] remove from prettier --- yarn-project/.prettierignore | 1 - 1 file changed, 1 deletion(-) diff --git a/yarn-project/.prettierignore b/yarn-project/.prettierignore index 21e584bfc3f..089b52962fe 100644 --- a/yarn-project/.prettierignore +++ b/yarn-project/.prettierignore @@ -6,4 +6,3 @@ boxes/*/src/artifacts/*.json boxes/*/src/artifacts/*.ts boxes/*/src/contracts/target/*.json *.md -end-to-end/src/docs_examples.test.ts