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

docs: update docs #3223

Merged
merged 23 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
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#installation).
critesjosh marked this conversation as resolved.
Show resolved Hide resolved

## Compile
critesjosh marked this conversation as resolved.
Show resolved Hide resolved

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

## Update

:::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).
critesjosh marked this conversation as resolved.
Show resolved Hide resolved
critesjosh marked this conversation as resolved.
Show resolved Hide resolved

:::

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`.

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 diffs.
critesjosh marked this conversation as resolved.
Show resolved Hide resolved

## 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.
2 changes: 2 additions & 0 deletions 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 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 a `noir_wasm` by default for compiling contracts. This helps reduce the developer overhead of maintaining compatible versions of `nargo`. You can still use `nargo` to compile contracts with `aztec-cli` by specifying the compiler:
critesjosh marked this conversation as resolved.
Show resolved Hide resolved

```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
71 changes: 23 additions & 48 deletions docs/docs/dev_docs/getting_started/aztecnr-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,7 @@ If you already have some experience with Noir and want to build a cooler contrac

## Install nargo
critesjosh marked this conversation as resolved.
Show resolved Hide resolved

`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: [email protected]
Compatible Nargo Version: 0.16.0-aztec.0
```
`Aztec.nr` is a framework built on top of [Noir](https://noir-lang.org), a zero-knowledge DSL. [Aztec CLI](../cli/main.md) comes with a built-in Noir compiler.

## Set up a project

Expand All @@ -52,29 +30,21 @@ 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.
Inside contracts create the following file structure:

Your file structure should look like this:

```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]
Expand All @@ -84,19 +54,14 @@ authors = [""]
compiler_version = "0.16.0"
critesjosh marked this conversation as resolved.
Show resolved Hide resolved

[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 +122,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 @@ -238,6 +203,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
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