Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docs): New getting started flow #2957

Merged
merged 52 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
0d6c439
update defi to DeFi, fmt
critesjosh Sep 29, 2023
c1a3a87
copy edits
critesjosh Sep 29, 2023
9cf72d7
edits
critesjosh Sep 29, 2023
d853c28
update roadmap section
critesjosh Sep 29, 2023
acb4c01
remove engineering roadmap links
critesjosh Sep 30, 2023
b6041c8
add intro section
critesjosh Sep 30, 2023
90f9c9e
Merge branch 'master' into docs/jc/add-intros-edits
critesjosh Oct 3, 2023
3a0f6c6
intermediate intro to contracts, state model, acconts, cross chain ca…
catmcgee Oct 4, 2023
fcdac25
intermediate concept circuits
catmcgee Oct 4, 2023
6741263
Merge branch 'docs/jc/add-intros-edits' of https://github.com/AztecPr…
critesjosh Oct 10, 2023
0bc566e
Merge branch 'master' into docs/jc/add-intros-edits
critesjosh Oct 10, 2023
cfc987f
remove bc deprecated
critesjosh Oct 10, 2023
9ee37fa
transactions and context
catmcgee Oct 19, 2023
ee78dde
conflicts
catmcgee Oct 19, 2023
bdf83ff
Merge branch 'master' into docs/jc/add-intros-edits
critesjosh Oct 20, 2023
0284b0f
remove deprecated assert_contains_and_remove
catmcgee Oct 20, 2023
b665fb6
small restructure
catmcgee Oct 22, 2023
61d3477
counter aztecnr getting started
catmcgee Oct 22, 2023
d6ce919
Merge remote-tracking branch 'origin/master' into new-getting-started…
catmcgee Oct 22, 2023
5ff640d
merge with master
catmcgee Oct 22, 2023
f6d7b16
merge master
catmcgee Oct 22, 2023
9f8510f
Resolved merge conflicts
catmcgee Oct 22, 2023
3c03445
accidental change
catmcgee Oct 22, 2023
2d5a3e2
accidental change
catmcgee Oct 22, 2023
4c6fe41
Merge branch 'master' into new-getting-started-flow
catmcgee Oct 23, 2023
b5cb9a4
minor edits to quickstart
critesjosh Oct 23, 2023
3c5bfaf
small edit
critesjosh Oct 23, 2023
85ce60b
include_code macro
catmcgee Oct 26, 2023
d479f90
Merge branch 'master' into new-getting-started-flow
catmcgee Oct 26, 2023
961994f
Merge branch 'master' into new-getting-started-flow
catmcgee Oct 26, 2023
81b9d2f
boxes reference
catmcgee Oct 26, 2023
57c7c33
Update docs/docs/dev_docs/cli/updating.md
catmcgee Oct 26, 2023
22ca5b0
.test.cpp
catmcgee Oct 26, 2023
49b1fe8
.test.cpp
catmcgee Oct 26, 2023
8f65418
josh feedback
catmcgee Oct 26, 2023
8ecf3c6
compile counter properly
catmcgee Oct 27, 2023
7125a75
docs broken link
catmcgee Oct 27, 2023
df9f809
Merge branch 'master' into new-getting-started-flow
catmcgee Oct 27, 2023
7d5e93d
Merge branch 'master' into new-getting-started-flow
catmcgee Oct 27, 2023
d563041
Merge branch 'new-getting-started-flow' of https://github.com/AztecPr…
critesjosh Oct 27, 2023
b101f9e
fix broken links
critesjosh Oct 27, 2023
4b5dd4f
fix build and breakup outputs
critesjosh Oct 27, 2023
bbbf3bd
Merge branch 'master' into new-getting-started-flow
catmcgee Oct 27, 2023
ed87274
revert some changes to get it building
critesjosh Oct 28, 2023
ff9535d
Merge branch 'master' into new-getting-started-flow
critesjosh Oct 28, 2023
4e5f51a
update test
catmcgee Oct 28, 2023
051a880
Merge branch 'master' into new-getting-started-flow
catmcgee Oct 28, 2023
57813fe
Merge branch 'master' into new-getting-started-flow
catmcgee Nov 2, 2023
8dedde2
compiler version update
catmcgee Nov 2, 2023
99f3372
redirects
catmcgee Nov 2, 2023
4e7ed50
Merge branch 'master' into new-getting-started-flow
catmcgee Nov 2, 2023
0037d58
Merge branch 'master' into new-getting-started-flow
critesjosh Nov 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ TEST_F(base_rollup_tests, native_new_commitments_tree)
// Then get sibling path so we can verify insert them into the tree.

std::array<PreviousKernelData<NT>, 2> kernel_data = { get_empty_kernel(), get_empty_kernel() };
std::array<NT::fr, MAX_NEW_COMMITMENTS_PER_TX* 2> new_commitments = { 0, 1, 2, 3, 4, 5, 6, 7 };
std::array<NT::fr, MAX_NEW_COMMITMENTS_PER_TX * 2> new_commitments = { 0, 1, 2, 3, 4, 5, 6, 7 };
for (uint8_t i = 0; i < 2; i++) {
std::array<fr, MAX_NEW_COMMITMENTS_PER_TX> kernel_commitments;
for (uint8_t j = 0; j < MAX_NEW_COMMITMENTS_PER_TX; j++) {
Expand Down Expand Up @@ -481,7 +481,7 @@ TEST_F(base_rollup_tests, native_nullifier_tree_regression)
initial_values[7] = uint256_t("2bb9aa4a22a6ae7204f2c67abaab59cead6558cde4ee25ce3464704cb2e38136");
initial_values[8] = uint256_t("16a732095298ccca828c4d747813f8bd46e188079ed17904e2c9de50760833c8");

std::array<fr, MAX_NEW_NULLIFIERS_PER_TX* 2> new_nullifiers = { 0 };
std::array<fr, MAX_NEW_NULLIFIERS_PER_TX * 2> new_nullifiers = { 0 };
new_nullifiers[0] = uint256_t("16da4f27fb78de7e0db4c5a04b569bc46382c5f471da2f7d670beff1614e0118"),
new_nullifiers[1] = uint256_t("26ab07ce103a55e29f11478eaa36cebd10c4834b143a7debcc7ef53bfdb547dd");

Expand Down Expand Up @@ -519,7 +519,7 @@ TEST_F(base_rollup_tests, native_nullifier_tree_regression)
TEST_F(base_rollup_tests, nullifier_tree_regression_2)
{
// Regression test caught when testing the typescript nullifier tree implementation
std::array<fr, MAX_NEW_NULLIFIERS_PER_TX* 2> new_nullifiers = { 0 };
std::array<fr, MAX_NEW_NULLIFIERS_PER_TX * 2> new_nullifiers = { 0 };
new_nullifiers[0] = uint256_t("2a7d956c1365d259646d2d85babe1abb793bb8789e98df7e2336a29a0c91fd01");
new_nullifiers[1] = uint256_t("236bf2d113f9ffee89df1a7a04890c9ad3583c6773eb9cdec484184f66abd4c6");
new_nullifiers[4] = uint256_t("2f5c8a1ee33c7104b244e22a3e481637cd501c9eae868cfab6b16e3b4ef3d635");
Expand All @@ -530,7 +530,7 @@ TEST_F(base_rollup_tests, nullifier_tree_regression_2)

TEST_F(base_rollup_tests, nullifier_tree_regression_3)
{
std::array<fr, MAX_NEW_NULLIFIERS_PER_TX* 2> new_nullifiers = { 0 };
std::array<fr, MAX_NEW_NULLIFIERS_PER_TX * 2> new_nullifiers = { 0 };
new_nullifiers[0] = uint256_t("0740a17aa6437e71836d2adcdcb3f52879bb869cdd9c8fb8dc39a12846cd17f2");
new_nullifiers[1] = uint256_t("282e0e2f38310a7c7c98b636830b66f3276294560e26ef2499da10892f00af8f");
new_nullifiers[4] = uint256_t("0f117936e888bd3befb4435f4d65300d25609e95a3d1563f62ef7e58c294f578");
Expand Down
65 changes: 65 additions & 0 deletions docs/docs/dev_docs/aztecjs/main.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
title: Aztec.js
---

If you are looking for the API reference, go [here](../../apis/aztec-js/index.md).

## Introduction

Aztec.js is a library that provides APIs for managing accounts and interacting with contracts on the Aztec network. It communicates with the [Private eXecution Environment (PXE)](https://docs.aztec.network/apis/pxe/interfaces/PXE) through a `PXE` implementation, allowing developers to easily register new accounts, deploy contracts, view functions, and send transactions.

## Usage

### Create a new account

```typescript
import { getSchnorrAccount } from "@aztec/aztec.js";
catmcgee marked this conversation as resolved.
Show resolved Hide resolved
import { GrumpkinPrivateKey } from "@aztec/types";

const encryptionPrivateKey = GrumpkinPrivateKey.random();
const signingPrivateKey = GrumpkinPrivateKey.random();
const wallet = getSchnorrAccount(
pxe,
encryptionPrivateKey,
signingPrivateKey
).waitDeploy();
console.log(`New account deployed at ${wallet.getAddress()}`);
```

### Deploy a 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}`);
```

### Send 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}`
);
```

### Call a view function

```typescript
import { Contract } from "@aztec/aztec.js";

const contract = await Contract.at(contractAddress, MyContractArtifact, wallet);
const balance = await contract.methods.getBalance(wallet.getAddress()).view();
console.log(`Account balance is ${balance}`);
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ There are also boxes that include a basic React interface (`blank-react`) and an

## Setup

See the Quickstart page for [requirements](./quickstart.md#requirements), starting the local [Sandbox environment](./quickstart.md#sandbox-installation) and [installing the CLI](./quickstart#cli-installation).
See the Quickstart page for [requirements](../getting_started/quickstart.md#requirements), starting the local [Sandbox environment](../getting_started/quickstart.md#sandbox-installation) and [installing the CLI](../getting_started/quickstart#cli-installation).

Aztec Boxes use [yarn](https://classic.yarnpkg.com/) for package management, so if you want to follow along exactly, make sure you have it [installed](https://classic.yarnpkg.com/en/docs/install).

Expand Down Expand Up @@ -68,7 +68,7 @@ yarn

### Start the Sandbox

See the Quickstart for [installing and starting the Sandbox](./quickstart.md#sandbox-installation).
See the Quickstart for [installing and starting the Sandbox](../getting_started/quickstart.md#sandbox-installation).

### Start the frontend

Expand Down
96 changes: 96 additions & 0 deletions docs/docs/dev_docs/cli/cli-commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
title: CLI Commands
---

Here you will find a reference to the commands available in the Aztec CLI.

## Installation

This command will install the Aztec CLI.

```bash
npm install -g @aztec/cli
```

## Creating Accounts

The first thing we want to do is create a couple of accounts. We will use the `create-account` command which will generate a new private key for us, register the account on the sandbox, and deploy a simple account contract which [uses a single key for privacy and authentication](../../concepts/foundation/accounts/keys.md):

#include_code create-account yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash

Once the account is set up, the CLI returns the resulting address, its privacy key, and partial address. You can read more about these [here](../../concepts/foundation/accounts/keys.md#addresses-partial-addresses-and-public-keys).

Save the Address and Private key as environment variables. We will be using them later.

```bash
export ADDRESS=<Address printed when you run the command>
export PRIVATE_KEY=<Private key printed when you run the command>
```

Alternatively, we can also manually generate a private key and use it for creating the account, either via a `-k` option or by setting the `PRIVATE_KEY` environment variable.

#include_code create-account-from-private-key yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash
catmcgee marked this conversation as resolved.
Show resolved Hide resolved

For all commands that require a user's private key, the CLI will look for the `PRIVATE_KEY` environment variable in absence of an optional argument.

Let's double check that the accounts have been registered with the sandbox using the `get-accounts` command:

#include_code get-accounts yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash

You will see a that a number of accounts exist that we did not create. The Sandbox initializes itself with 3 default accounts. Save one of the printed accounts (not the one that you generated above) in an environment variable. We will use it later.

```bash
export ADDRESS2=<Account address printed by the above command>
```

## Deploying a Token Contract

We will now deploy a token contract using the `deploy` command, and set an address of the admin via a constructor argument. You can find the contract we are deploying [here](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr) (or write it for yourself in [this tutorial!](../tutorials/writing_token_contract.md))
Make sure to replace this address with one of the two you created earlier.

#include_code deploy yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash

Save the contract address as an environment variable. We will use it later.

```bash
export CONTRACT_ADDRESS=<Your new contract address>
```

- `--args` - Arguments to the constructor of the contract. In this case we have set an address as admin.

The CLI tells us that the contract was successfully deployed. We can use the `check-deploy` command to verify that a contract has been successfully deployed to that address:

#include_code check-deploy yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash

## Sending a Transaction

We can now send a transaction to the network. We will mint funds in the public domain.
To form and submit the transaction we will use the `send` command of `aztec-cli`.
The `send` command expect the function name as the first unnamed argument and the following named arguments:

- `--args` - The list of arguments to the function call.
- `--contract-artifact` - The artifact of the contract to call.
- `--contract-address` - The deployed address of the contract to call.
- `--private-key` - The private key of the sender.

#include_code send yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash

We called the [`mint_public`](https://github.com/AztecProtocol/aztec-packages/blob/87fa621347e55f82e36c70515c1824161eee5282/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr#L157C10-L157C10) function and provided it with the 2 arguments it expects: the recipient's address and the amount to be minted. Make sure to replace all addresses in this command with yours.

The command output tells us the details of the transaction such as its hash and status. We can use this hash to query the receipt of the transaction at a later time:

#include_code get-tx-receipt yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash

## Calling an Unconstrained (View) Function

Now that the `mint_public` tx has been settled we can call the `balance_of_public` unconstrained function:

#include_code call yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash

The `call` command calls a read-only method on a contract, one that will not generate a transaction to be sent to the network. The arguments here are:

- `--args` - The address for which we want to retrieve the balance.
- `--contract-artifact` - The artifact of the contract we are calling.
- `--contract-address` - The address of the deployed contract

As you can see from the result, this address has a public balance of 543, as expected.
151 changes: 23 additions & 128 deletions docs/docs/dev_docs/cli/main.md
Original file line number Diff line number Diff line change
@@ -1,144 +1,39 @@
---
title: Aztec CLI
title: Sandbox and CLI
---

## Introduction
The Aztec Sandbox is an environment for local development on the Aztec Network. It's easy to get setup with just a single, simple command, and contains all the components needed to develop and test Aztec contracts and applications. The Aztec CLI will allow you to interact with the sandbox.

The Aztec CLI is a command-line tool allowing the user to interact directly with the Aztec Network.
## Components of the Aztec network

It aims to provide all of the functionality required to deploy and invoke contracts and query system state such as contract data, transactions and emitted logs.

## Requirements

You should have [node.js](https://nodejs.org/en/download) installed with version >= 18.

To install the Aztec CLI run:

```bash
npm install -g @aztec/cli
```

Or if you use yarn:

```bash
yarn global add @aztec/cli
```

Then verify that it is installed with:

```bash
aztec-cli -h
```

Once installed it is invoked via:

`aztec-cli [options] [command]`

## I have the Sandbox running, now what?

Lets first establish that we are able to communicate with the Sandbox. Most commands will require the url to the Sandbox, which defaults in the CLI to `http://localhost:8080`. You can override this as an option with each command or by setting `PXE_URL` environment variable.

To test communication with the Sandbox, let's run the command:

#include_code block-number yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash

You should see the current block number (1) printed to the screen!

## Contracts

We have shipped a number of example contracts in the `@aztec/noir-contracts` npm package. This is included with the cli by default so you are able to use these contracts to test with. To get a list of the names of the contracts run:

#include_code example-contracts yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash

You can see all of our example contracts in the monorepo [here](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/noir-contracts/src/contracts).

In the following sections there will be commands that require contracts as options. You can either specify the full directory path to the contract artifact, or you can use the name of one of these examples as the option value. This will become clearer later on.

## Creating Accounts

The first thing we want to do is create a couple of accounts. We will use the `create-account` command which will generate a new private key for us, register the account on the sandbox, and deploy a simple account contract which [uses a single key for privacy and authentication](../../concepts/foundation/accounts/keys.md):

#include_code create-account yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash
Aztec's Layer 2 network is a fully programmable combined private/public ZK rollup. To achieve this, the network contains the following primary components:

Once the account is set up, the CLI returns the resulting address, its privacy key, and partial address. You can read more about these [here](../../concepts/foundation/accounts/keys.md#addresses-partial-addresses-and-public-keys).
- Aztec Node - Aggregates all of the 'backend' services necessary for the building and publishing of rollups. This packages is currently in development and much of the functionality is mocked.
- [Private Execution Environment (PXE)](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/pxe) - Normally residing with the end client, this decrypts and stores a client's private state, executes simulations and submits transactions to the Aztec Node.
- [Aztec.js](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/aztec.js) - Aztec's client library for interacting with the PXE (think Ethers.js). See the getting started guide [here](../getting_started/aztecjs-getting-started.md).

Save the Address and Private key as environment variables. We will be using them later.
All of this is included in the Sandbox, with the exception of Aztec.js which you can use to interact with it.

```bash
export ADDRESS=<Address printed when you run the command>
export PRIVATE_KEY=<Private key printed when you run the command>
```
With the help of Aztec.js you will be able to:

Alternatively, we can also manually generate a private key and use it for creating the account, either via a `-k` option or by setting the `PRIVATE_KEY` environment variable.
- Create an account
- Deploy a contract
- Call view methods on contracts
- Simulate the calling of contract functions
- Send transactions to the network
- Be notified when transactions settle
- Query chain state such as chain id, block number etc.

#include_code create-account-from-private-key yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash
## What's in the Sandbox?

For all commands that require a user's private key, the CLI will look for the `PRIVATE_KEY` environment variable in absence of an optional argument.
The sandbox contains a local Ethereum instance running [Anvil](https://book.getfoundry.sh/anvil/), a local instance of the Aztec rollup, an aztec private execution client for handling user transactions and state, and, if using Docker, an [Otterscan](https://github.com/otterscan/otterscan) block explorer for the local Ethereum network.

Let's double check that the accounts have been registered with the sandbox using the `get-accounts` command:
These provide a self contained environment which deploys Aztec on a local (empty) Ethereum network, creates 3 smart contract wallet accounts on the rollup, and allows transactions to be processed on the local Aztec sequencer.

#include_code get-accounts yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash
The current sandbox does not generate or verify proofs, but provides a working end to end developer flow for writing and interacting with Aztec.nr smart contracts.

You will see a that a number of accounts exist that we did not create. The Sandbox initializes itself with 3 default accounts. Save one of the printed accounts (not the one that you generated above) in an environment variable. We will use it later.
## Aztec CLI

```bash
export ADDRESS2=<Account address printed by the above command>
```
The Aztec CLI is a command-line tool allowing the user to interact directly with the Aztec network and sandbox.

## Deploying a Token Contract

We will now deploy a token contract using the `deploy` command, and set an address of the admin via a constructor argument.
Make sure to replace this address with one of the two you created earlier.

#include_code deploy yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash

Save the contract address as an environment variable. We will use it later.

```bash
export CONTRACT_ADDRESS=<Your new contract address>
```

- `--args` - Arguments to the constructor of the contract. In this case we have set an address as admin.

The CLI tells us that the contract was successfully deployed. We can use the `check-deploy` command to verify that a contract has been successfully deployed to that address:

#include_code check-deploy yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash

## Sending a Transaction

We can now send a transaction to the network. We will mint funds in the public domain.
To form and submit the transaction we will use the `send` command of `aztec-cli`.
The `send` command expect the function name as the first unnamed argument and the following named arguments:

- `--args` - The list of arguments to the function call.
- `--contract-artifact` - The artifact of the contract to call.
- `--contract-address` - The deployed address of the contract to call.
- `--private-key` - The private key of the sender.

#include_code send yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash

We called the `mint_public` function and provided it with the 2 arguments it expects: the recipient's address and the amount to be minted. Make sure to replace all addresses in this command with yours.

The command output tells us the details of the transaction such as its hash and status. We can use this hash to query the receipt of the transaction at a later time:

#include_code get-tx-receipt yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash

## Calling an Unconstrained (View) Function

Now that the `mint_public` tx has been settled we can call the `balance_of_public` unconstrained function:

#include_code call yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash

The `call` command calls a read-only method on a contract, one that will not generate a transaction to be sent to the network. The arguments here are:

- `--args` - The address for which we want to retrieve the balance.
- `--contract-artifact` - The artifact of the contract we are calling.
- `--contract-address` - The address of the deployed contract

As you can see from the result, this address has a public balance of 543, as expected.

## Compute Function Selector
`aztec-cli --compute-selector <signature e.g. foo(Field,Field)>` gives the function selector.

## Inspect Contract
`aztec-cli --compute-selector <json artifact file e.g. artifacts/token_contract.json>` gives the list of all callable functions along with their function signature and selector.
It aims to provide all of the functionality required to deploy and invoke contracts and query system state such as contract data, transactions and emitted logs.
Loading