Skip to content

Commit

Permalink
docs: update docs (#3223)
Browse files Browse the repository at this point in the history
This PR aims to update the docs with latest changes in the CLI
(noir_wasm & `update` command)

Relates to #3195 

# Checklist:
Remove the checklist to signal you've completed it. Enable auto-merge if
the PR is ready to merge.
- [ ] If the pull request requires a cryptography review (e.g.
cryptographic algorithm implementations) I have added the 'crypto' tag.
- [ ] I have reviewed my diff in github, line by line and removed
unexpected formatting changes, testing logs, or commented-out code.
- [ ] Every change is related to the PR description.
- [ ] I have
[linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
this pull request to relevant issues (if any exist).

---------

Co-authored-by: Josh Crites <jc@joshcrites.com>
Co-authored-by: josh crites <critesjosh@gmail.com>
Co-authored-by: Rahul Kothari <rahul.kothari.201@gmail.com>
  • Loading branch information
4 people authored Nov 7, 2023
1 parent 2d50f11 commit 7977064
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 191 deletions.
33 changes: 33 additions & 0 deletions docs/docs/dev_docs/cli/cli-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,45 @@ Here you will find a reference to the commands available in the Aztec CLI.

## Installation

### NPM

This command will install the Aztec CLI.

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

### Docker

The CLI will be installed automatically via Docker if it is not already found locally, by running the command to install and start the sandbox, [instructions here](./sandbox-reference.md#with-docker).

## Update

The CLI comes with an update command.

```bash
npx @aztec/cli@latest update . --contract src/contract1 --contract src/contract2
```

This command does a few things to manage updates:

- If you installed the CLI globally via a node package manager, it updates to the specified version. Defaults to latest.
- It looks for a `package.json` and updates all `@aztec/` dependencies to the versions the sandbox expects.
- It looks for `Nargo.toml` at the `--contract` paths specified and updates all `aztec.nr` dependencies to the versions the sandbox expects.
- It outputs the changes.

The sandbox must be running for the update command to work unless there the project defines `@aztec/aztec-sandbox` as a dependency, in which case the command will compare against the version listed in `package.json`.

:::info

If you installed the CLI via Docker (with the sandbox install Docker command), the `aztec-cli update` command won't work. You can update the CLI it by [running the command again](./sandbox-reference.md#installation-with-docker).

:::

## Compile

You can find more information about compiling contracts [on this page](../contracts/compiling.md).

## 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):
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/dev_docs/cli/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ The current sandbox does not generate or verify proofs, but provides a working e

The Aztec CLI is a command-line tool allowing the user to interact directly with the Aztec network and sandbox.

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.
It aims to provide all of the functionality required to deploy, compile, and invoke contracts and query system state such as contract data, transactions and emitted logs.
6 changes: 5 additions & 1 deletion docs/docs/dev_docs/cli/sandbox-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ You can run the Sandbox using either Docker or npm.

This will attempt to run the Sandbox on ` localhost:8080`. You can change the port defined in `./.aztec/docker-compose.yml`. Running the command again will overwrite any changes made to the `docker-compose.yml`.

If you don't have the CLI installed via a node package manager, this command will also install or update the CLI.

To install a specific version of the sandbox, you can set the environment variable `SANDBOX_VERSION`

```bash
Expand All @@ -31,9 +33,11 @@ You can download and run the Sandbox package directly if you have nodejs 18 or h
You will also need an Ethereum node like Anvil or Hardhat running locally on port 8545.

```bash
npx @aztec/aztec-sandbox
npx @aztec/aztec-sandbox @aztec/aztec-cli
```

You can read [this tutorial on how to use the npm package](../tutorials/testing.md#running-sandbox-in-the-nodejs-process)

## Running

The installation command will run the sandbox, and once installed you can run like so:
Expand Down
25 changes: 11 additions & 14 deletions docs/docs/dev_docs/contracts/compiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,9 @@ In this guide we will cover how to do so, both using the CLI and programmaticall

We'll also cover how to generate a helper [TypeScript interface](#typescript-interfaces) and an [Aztec.nr interface](#noir-interfaces) for easily interacting with your contract from your typescript app and from other Aztec.nr contracts, respectively.

## Prerequisites

You will need the Noir build tool `nargo`, which you can install via [`noirup`](https://github.com/noir-lang/noirup). Make sure you install the correct version of nargo:

<InstallNargoInstructions />

:::info
You can run `aztec-cli get-node-info` to query the version of nargo that corresponds to your current installation.
:::

## Compile using the CLI

To compile a contract using the Aztec CLI, first install it:

`npm install -g @aztec/cli`
To compile a contract using the Aztec CLI, first [install it](../cli/cli-commands#installation).

Then run the `compile` command with the path to your [contract project folder](./layout.md#directory-structure), which is the one that contains the `Nargo.toml` file:

Expand All @@ -30,6 +18,14 @@ aztec-cli compile ./path/to/my_aztec_contract_project

This will output a JSON [artifact](./artifacts.md) for each contract in the project to a `target` folder containing their artifact, which you can use for deploying or interacting with your contracts.

`aztec-cli` uses `noir_wasm` by default for compiling contracts. This helps reduce the developer overhead of installation and maintaining the noir compiler, `nargo`. However, if you prefer, you can use `nargo` to compile contracts with `aztec-cli` as so:

```bash
aztec-cli compile my-contract --compiler nargo # switches compiler to nargo
```

When you specify `nargo` as your compiler, you need to make sure that you are using the correct version. You can find the [latest version information here](../updating.md#updating-nargo).

### Typescript Interfaces

You can use the compiler to autogenerate type-safe typescript classes for each of your contracts. These classes define type-safe methods for deploying and interacting with your contract based on their artifact.
Expand Down Expand Up @@ -247,7 +243,8 @@ You can also programmatically access the compiler via the `@aztec/noir-compiler`

The compiler exposes the following functions:

- `compileUsingNargo`: Compiles an Aztec.nr project in the target folder using the `nargo` binary available on the shell `PATH` and returns the generated ABIs.
- `compileUsingNoirWasm`: Compiles an Aztec.nr project in the target folder using a WASM build of the compiler and returns the generated ABIs.
- `compileUsingNargo`: Does the same as `compileUsingNargo` but instead of WASM it uses the `nargo` binary available on the shell `PATH`
- `generateTypescriptContractInterface`: Generates a typescript class for the given contract artifact.
- `generateNoirContractInterface`: Generates a Aztec.nr interface struct for the given contract artifact.

Expand Down
8 changes: 5 additions & 3 deletions docs/docs/dev_docs/contracts/deploying.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ Pre-requisite - Generate type-safe typescript classes for your contract when com

```ts
import { readFileSync, writeFileSync } from "fs";
import { createConsoleLogger } from "@aztec/foundation/log";
import {
compileUsingNargo,
compileUsingNoirWasm,
generateTypescriptContractInterface,
} from "@aztec/noir-compiler";

const compiled: ContractArtifact[] = await compileUsingNargo(
projectPathToContractFolder
const compiled: ContractArtifact[] = await compileUsingNoirWasm(
projectPathToContractFolder,
{ log: createConsoleLogger() }
);
const abiImportPath = "../target/Example.json";
writeFileSync(
Expand Down
16 changes: 12 additions & 4 deletions docs/docs/dev_docs/contracts/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@ An **Aztec smart contract** is a smart contract with **private** state variables

## Install Noir

To write an Aztec.nr contract, you need to write Noir, which requires a build tool called Nargo:

<InstallNargoInstructions />
To write an Aztec.nr contract, you need to write Noir, [aztec-cli](../cli/cli-commands) comes with a built-in compiler for Noir contracts.

:::info
For those coming from vanilla Noir, the nargo version used for aztec.nr is tracked seaprately to nargo for vanilla noir, so be sure to use the nargo version shown above
For those coming from vanilla Noir, the version used for aztec.nr is tracked separately to nargo for vanilla noir, so be sure to use the nargo version shown above
:::

## Install `nargo` (recommended)

The CLI comes with the Noir compiler, so installing `nargo` is not required, however it is recommended as it provides a better developer experience for writing contracts. You will need nargo installed to take advantage of the [Noir Language Server](https://noir-lang.org/nargo/language_server), which provides syntax highlighting and formatting for your Aztec contracts.

You will also need `nargo` if you want to run unit tests in Noir.

You can install `nargo` with the following commands:

<InstallNargoInstructions />

## Install Noir tooling

There are a number of tools to make writing Aztec.nr contracts more pleasant. See [here](https://github.com/noir-lang/awesome-noir#get-coding).
Expand Down
77 changes: 24 additions & 53 deletions docs/docs/dev_docs/getting_started/aztecnr-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,6 @@ If you already have some experience with Noir and want to build a cooler contrac
- You have followed the [quickstart](./quickstart.md)
- Running Aztec Sandbox

## Install nargo

`Aztec.nr` is a framework built on top of [Noir](https://noir-lang.org), a zero-knowledge DSL. Nargo is the build tool for Noir, similar to cargo for Rust. We need it for compiling our smart contracts.

<InstallNargoInstructions />

You can check it has been installed correctly by running:

```bash
aztec-cli get-node-info
```

It should print something similar to:

```bash
~ aztec-cli get-node-info

Node Info:

Version: 1
Chain Id: 31337
Rollup Address: 0xcf7ed3acca5a467e9e704c703e8d87f634fb0fc9
Client: pxe@0.7.5
Compatible Nargo Version: 0.16.0-aztec.0
```

## Set up a project

Create a new directory called `aztec-private-counter`
Expand All @@ -52,51 +26,38 @@ cd aztec-private-counter
mkdir contracts
```

Inside `contracts`, create a new Noir project using nargo:

```bash
cd contracts
nargo new counter --contract
```

The `contract` flag will create a contract nargo project rather than using vanilla Noir.

Your file structure should look like this:
Inside contracts create the following file structure:

```bash
aztec-private-counter
|-contracts
| |--counter
| | |--src
| | | |--main.nr
| | |Nargo.toml
```tree
.
|-aztec-private-counter
| |-contracts
| | |--counter
| | | |--src
| | | | |--main.nr
| | | |--Nargo.toml
```

The file `main.nr` will soon turn into our smart contract!

Your `Nargo.toml` file should look something like this:
Add the following content to `Nargo.toml`:

```toml
[package]
name = "counter"
type = "contract"
authors = [""]
compiler_version = "0.16.0"
compiler_version = ">=0.18.0"

[dependencies]
```

Add the following dependencies under `[dependencies]`:

```toml
aztec = { git="https://github.com/AztecProtocol/aztec-packages", tag="#include_aztec_version", directory="yarn-project/aztec-nr/aztec" }
value_note = { git="https://github.com/AztecProtocol/aztec-packages", tag="#include_aztec_version", directory="yarn-project/aztec-nr/value-note"}
easy_private_state = { git="https://github.com/AztecProtocol/aztec-packages", tag="#include_aztec_version", directory="yarn-project/aztec-nr/easy-private-state"}
```

## Define the functions

Go to `main.nr` and replace the code with this contract initialization:
Go to `main.nr` and start with this contract initialization:

```rust
contract Counter {
Expand Down Expand Up @@ -157,7 +118,7 @@ We have annotated this and other functions with `#[aztec(private)]` which are AB

## Incrementing our counter

Now let’s implement the `increment` functio we defined in the first step.
Now let’s implement the `increment` function we defined in the first step.

#include_code increment /yarn-project/noir-contracts/src/contracts/counter_contract/src/main.nr rust

Expand Down Expand Up @@ -228,7 +189,7 @@ Partial Address: 0x211edeb823ef3e042e91f338d0d83d0c90606dba16f678c701d8bb64e64e2

Use one of these `address`es as the `owner`. You can either copy it or export.

To deploy the counter contract, [ensure the sandbox is running](../cli/sandbox-reference.md) and run this in the root of your nargo project:
To deploy the counter contract, [ensure the sandbox is running](../cli/sandbox-reference.md) and run this in the root of your Noir project:

```bash
aztec-cli deploy target/Counter.json --args 100 0x25048e8c1b7dea68053d597ac2d920637c99523651edfb123d0632da785970d0
Expand All @@ -238,6 +199,16 @@ You can also test the functions by applying what you learned in the [quickstart]

Congratulations, you have now written, compiled, and deployed your first Aztec.nr smart contract!

## Install `nargo` (recommended)

The CLI comes with the Noir compiler, so installing `nargo` is not required, however it is recommended as it provides a better developer experience for writing contracts. You will need nargo installed to take advantage of the [Noir Language Server](https://noir-lang.org/nargo/language_server), which provides syntax highlighting and formatting for your Aztec contracts.

You will also need `nargo` if you want to run unit tests in Noir.

You can install `nargo` with the following commands:

<InstallNargoInstructions />

## What's next?

Now you can explore.
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/dev_docs/getting_started/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ To install the latest Sandbox version, run:

This will attempt to run the Sandbox on ` localhost:8080`, so you will have to make sure nothing else is running on that port or change the port defined in `./.aztec/docker-compose.yml`. Running the command again will overwrite any changes made to the `docker-compose.yml`.

Alternatively, you can [run the sandbox as an npm package](../cli/sandbox-reference.md#with-npm).

## Install the CLI

To interact with the Sandbox now that it's running locally, install the [Aztec CLI](https://www.npmjs.com/package/@aztec/cli):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ In this step we will start writing our Aztec.nr bridge smart contract and write

## Initial contract setup

In our `token-bridge` nargo project in `aztec-contracts`, under `src` there is an example `main.nr` file. Delete all the code in here and paste this to define imports and initialize the constructor:
In our `token-bridge` Noir project in `aztec-contracts`, under `src` there is an example `main.nr` file. Delete all the code in here and paste this to define imports and initialize the constructor:

```rust
mod util;
Expand Down
32 changes: 11 additions & 21 deletions docs/docs/dev_docs/tutorials/token_portal/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ In this step, we’re going to

1. Install prerequisites
2. Create a yarn project to house everything
3. Create a nargo project for our Aztec contract
3. Create a noir project for our Aztec contract
4. Create a hardhat project for our Ethereum contract(s)
5. Import all the Ethereum contracts we need
6. Create a yarn project that will interact with our contracts on L1 and the sandbox
Expand All @@ -20,18 +20,12 @@ However if you’d rather skip this part, our dev-rels repo contains the starter
- [node v18+](https://github.com/tj/n)
- [docker](https://docs.docker.com/)
- [Aztec sandbox](https://docs.aztec.network/dev_docs/getting_started/sandbox) - you should have this running before starting the tutorial
- [Aztec CLI](../../getting_started/quickstart.md)

```bash
/bin/sh -c "$(curl -fsSL 'https://sandbox.aztec.network')"
```

- Nargo

```bash
curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | sh
noirup -v #include_noir_version
```

# Create the root project and packages

Our root project will house everything ✨
Expand All @@ -43,19 +37,11 @@ cd aztec-token-bridge && mkdir packages

We will hold our projects inside of `packages` to follow the design of the project in the [repo](https://github.com/AztecProtocol/dev-rel/tree/main/tutorials/token-bridge-e2e).

# Create a nargo project
# Create a noir project

Now inside `packages` create a new directory called `aztec-contracts`

Inside `aztec-contracts`, create a nargo contract project by running

```bash
mkdir aztec-contracts
cd aztec-contracts
nargo new --contract token_bridge
```

Your structure will look something like this
Inside `aztec-contracts`, create the following file structure:

```
aztec-contracts
Expand All @@ -65,17 +51,21 @@ aztec-contracts
├── main
```

Inside `Nargo.toml` you will need to add some dependencies. Put this at the bottom:
Inside `Nargo.toml` add the following content:

```toml
[package]
name = "token_bridge"
authors = [""]
compiler_version = ">=0.18.0"
type = "contract"

[dependencies]
aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/aztec" }
value_note = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/value-note"}
safe_math = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/safe-math"}
```

Inside `src` you will see a `main.nr` file. This is where our main smart contract will go.

We will also be writing some helper functions that should exist elsewhere so we don't overcomplicated our contract. In `src` create two more files - one called `util.nr` and one called `token_interface` - so your dir structure should now look like this:

```
Expand Down
Loading

0 comments on commit 7977064

Please sign in to comment.