diff --git a/.circleci/config.yml b/.circleci/config.yml index 7868a06e5da..365a253a62d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -884,7 +884,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 @@ -906,6 +905,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: @@ -1342,6 +1352,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 @@ -1387,6 +1398,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 5fda30f7f2d..0e5cbbbd258 100644 --- a/docs/docs/developers/aztecjs/guides/call_view_function.md +++ b/docs/docs/developers/aztecjs/guides/call_view_function.md @@ -6,10 +6,29 @@ 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"; +## 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: + +#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 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}`); -``` 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..ffa565f33fa 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 + +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 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..12d1fb9c0ab --- /dev/null +++ b/yarn-project/end-to-end/src/docs_examples.test.ts @@ -0,0 +1,46 @@ +// 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'; +// 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, 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 + .send() + .deployed(); +// docs:end:deploy_contract + +// 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().wait(); +// docs:end:send_transaction + +// docs:start:call_view_function +const _balance = await contract.methods.getBalance(wallet.getAddress()).view(); +// docs:end:call_view_function