Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ba43c73
getting-started and sandbox
catmcgee Jan 29, 2024
0b9bb61
Merge branch 'master' into docs/dip1-howtos
catmcgee Jan 29, 2024
4928aca
contracts
catmcgee Jan 29, 2024
5a01264
netlifytoml
catmcgee Jan 29, 2024
abd01da
update counter contract example
catmcgee Jan 29, 2024
477fa36
sidebar
catmcgee Jan 30, 2024
2c962a1
some links
catmcgee Jan 30, 2024
2d84e16
Merge branch 'master' into docs/dip1-howtos
catmcgee Jan 31, 2024
14bd967
Merge branch 'master' into docs/dip1-howtos
catmcgee Jan 31, 2024
b328393
syntax -> writing_a_contract
catmcgee Jan 31, 2024
a6518ea
fit bb
catmcgee Jan 31, 2024
bb8e20c
fix bb
catmcgee Jan 31, 2024
a2a46f2
Merge branch 'master' into docs/dip1-howtos
catmcgee Jan 31, 2024
335d91a
mistakes
catmcgee Jan 31, 2024
bd3a28a
bunch of paths
catmcgee Jan 31, 2024
642ced1
Merge branch 'master' into docs/dip1-howtos
catmcgee Jan 31, 2024
01bdf09
how to accounts
catmcgee Jan 31, 2024
16dc4c4
Merge branch 'docs/dip1-howtos' of https://github.com/AztecProtocol/a…
catmcgee Jan 31, 2024
68f8b14
mistakes
catmcgee Jan 31, 2024
4acfee4
bb
catmcgee Jan 31, 2024
5532126
Merge branch 'master' into docs/dip1-howtos
Feb 2, 2024
681bd14
Merge branch 'master' into docs/dip1-howtos
catmcgee Feb 2, 2024
35bf27f
almost finished
Feb 2, 2024
fc04a4a
update testing sidebar
Feb 2, 2024
f90f1a2
Merge branch 'master' into docs/dip1-howtos
catmcgee Feb 2, 2024
7f63276
josh suggestions
Feb 6, 2024
25b0874
code formatting
catmcgee Feb 6, 2024
af638bd
merge conflicts
catmcgee Feb 6, 2024
d0d400f
bb format
catmcgee Feb 6, 2024
d53cf69
bb format
catmcgee Feb 6, 2024
2eb4e52
build errors
catmcgee Feb 6, 2024
c874a46
Merge remote-tracking branch 'origin/master' into docs/dip1-howtos
catmcgee Feb 7, 2024
40ecda8
merge conflicts
catmcgee Feb 7, 2024
d8d6103
merge conflicts
catmcgee Feb 7, 2024
8270625
Merge remote-tracking branch 'origin/master' into docs/dip1-howtos
catmcgee Feb 9, 2024
ebefe79
merge conflicts
catmcgee Feb 9, 2024
574eaf8
update slow updates tree to remove storage init ref
catmcgee Feb 9, 2024
845b913
pls build 🥺👉👈
catmcgee Feb 9, 2024
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
15 changes: 15 additions & 0 deletions docs/docs/developers/aztecjs/guides/call_view_function.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: How to Call a View Function
---

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we link the reference code to source somewhere, so if the API changes the docs automatically reflect that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i cant find it anywhere in the monorepo. only overcomplicated examples. wdyt?

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}`);
```
21 changes: 21 additions & 0 deletions docs/docs/developers/aztecjs/guides/create_account.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: How to Create a New Account
---

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we link the reference code to source somewhere, so if the API changes the docs automatically reflect that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()}`);
```
18 changes: 18 additions & 0 deletions docs/docs/developers/aztecjs/guides/deploy_contract.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: How to Deploy a Contract
---

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we link the reference code to source somewhere, so if the API changes the docs automatically reflect that?

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

const contract = await Contract.deploy(wallet, MyContractArtifact, [
...constructorArgs,
])
.send()
.deployed();
console.log(`Contract deployed at ${contract.address}`);
```
20 changes: 20 additions & 0 deletions docs/docs/developers/aztecjs/guides/send_transaction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: How to Send a Transaction
---

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we link the reference code to source somewhere, so if the API changes the docs automatically reflect that?

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}`
);
```
63 changes: 11 additions & 52 deletions docs/docs/developers/aztecjs/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,23 @@
title: Aztec.js
---

If you are looking for the API reference, go [here](../../apis/aztec-js/index.md).
If you are looking for the Aztec.js 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";
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()}`);
```

### 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
## Guides

```typescript
import { Contract } from "@aztec/aztec.js";
- [How to create a new account](./guides/create_account.md)
- [How to deploy a smart contract](./guides/deploy_contract.md)
- [How to send a transaction](./guides/send_transaction.md)
- [How to call a view function](./guides/call_view_function.md)

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

### Call a view function
- [Aztec.js Reference](../../apis/aztec-js/index.md)
- [Accounts Reference](../../apis/accounts/index.md)

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

const contract = await Contract.at(contractAddress, MyContractArtifact, wallet);
const balance = await contract.methods.getBalance(wallet.getAddress()).view();
console.log(`Account balance is ${balance}`);
```
- [An example of testing with Aztec.js](../tutorials/testing.md)
22 changes: 0 additions & 22 deletions docs/docs/developers/contracts/abi.md

This file was deleted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update the typescript Token interface to be referencing source code instead of hard coded?

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Compiling contracts
---
title: How to compile a contract
---

Once you have written a [contract](../contracts/main.md) in Aztec.nr, you will need to compile it into an [artifact](./artifacts.md) in order to use it.
Once you have written a [contract](../main.md) in Aztec.nr, you will need to compile it into an [artifact](./artifacts.md) in order to use it.

In this guide we will cover how to do so, both using the CLI and programmatically.

Expand All @@ -10,7 +12,7 @@ We'll also cover how to generate a helper [TypeScript interface](#typescript-int

To compile a contract using the Aztec's build of nargo.

Run the `aztec-nargo compile` command within your [contract project folder](./layout.md#directory-structure), which is the one that contains the `Nargo.toml` file:
Run the `aztec-nargo compile` command within your [contract project folder](../writing_contracts/layout.md), which is the one that contains the `Nargo.toml` file:

```bash
aztec-nargo compile
Expand Down Expand Up @@ -111,11 +113,11 @@ export class TokenContract extends ContractBase {
}
```

Read more about interacting with contracts using `aztec.js` [here](../getting_started/aztecjs-getting-started.md).
Read more about interacting with contracts using `aztec.js` [here](../../getting_started/aztecjs-getting-started.md).

### Aztec.nr interfaces

An Aztec.nr contract can [call a function](./syntax/functions/main.md) in another contract via `context.call_private_function` or `context.call_public_function`. However, this requires manually assembling the function selector and manually serializing the arguments, which is not type-safe.
An Aztec.nr contract can [call a function](../writing_contracts/functions/call_functions.md) in another contract via `context.call_private_function` or `context.call_public_function`. However, this requires manually assembling the function selector and manually serializing the arguments, which is not type-safe.

To make this easier, the compiler can generate contract interface structs that expose a convenience method for each function listed in a given contract artifact. These structs are intended to be used from another contract project that calls into the current one. For each contract, two interface structs are generated: one to be used from private functions with a `PrivateContext`, and one to be used from open functions with a `PublicContext`.

Expand Down Expand Up @@ -209,15 +211,15 @@ impl TokenPublicContextInterface {
}
```

Read more about how to use the Aztec.nr interfaces [here](./syntax/functions/main.md).
Read more about how to use the Aztec.nr interfaces [here](../writing_contracts/functions/main.md).

:::info
At the moment, the compiler generates these interfaces from already compiled ABIs, and not from source code. This means that you should not import a generated interface from within the same project as its source contract, or you risk circular references.
:::

## Next steps

Once you have compiled your contracts, you can use the generated artifacts via the `Contract` class in the `aztec.js` package to deploy and interact with them, or rely on the type-safe typescript classes directly. Alternatively, use the CLI [to deploy](../../developers/cli/main.md#deploying-a-token-contract) and [interact](../../developers/cli/main.md#sending-a-transaction) with them.
Once you have compiled your contracts, you can use the generated artifacts via the `Contract` class in the `aztec.js` package to deploy and interact with them, or rely on the type-safe typescript classes directly. Alternatively, use the CLI [to deploy](../../sandbox/references/cli-commands.md#deploying-a-token-contract) and [interact](../../sandbox/references/cli-commands.md#calling-an-unconstrained-view-function) with them.

import Disclaimer from "../../misc/common/\_disclaimer.mdx";
import Disclaimer from "../../../misc/common/\_disclaimer.mdx";
<Disclaimer/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update the hard coded snippets to reference source code instead?

Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
---
title: How to deploy a contract
---

# Deploying contracts

Once you have [compiled](./compiling.md) your contracts you can proceed to deploying them using the aztec-cli or using aztec.js which is a Typescript client to interact with the sandbox.
Once you have [compiled](../compiling_contracts/how_to_compile_contract.md) your contracts you can proceed to deploying them using the aztec-cli or using aztec.js which is a Typescript client to interact with the sandbox.

## Prerequisites

- `aztec-cli` and `aztec-nargo` installed (go to [CLI main section](../cli/main.md) for installation instructions)
- contract artifacts ready (go to [Compiling contracts section](./compiling.md) for instructions on how to compile contracts)
- Aztec Sandbox running (go to [Sandbox section](../getting_started/quickstart.md) for instructions on how to install and run the sandbox)
- `aztec-cli` and `aztec-nargo` installed (go to [Sandbox and CLI section](../../sandbox/main.md) for installation instructions)
- contract artifacts ready (go to [How to Compile Contract](../compiling_contracts/how_to_compile_contract.md) for instructions on how to compile contracts)
- Aztec Sandbox running (go to [Sandbox section](../../getting_started/quickstart.md) for instructions on how to install and run the sandbox)

## Deploy

Expand Down Expand Up @@ -39,7 +43,7 @@ Generate the typescript class:
aztec-cli codegen ./aztec-nargo/output/target/path -o src/artifacts --ts
```

This would create a typescript file like `Example.ts` in `./src/artifacts`. Read more on the [compiling page](./compiling.md).
This would create a typescript file like `Example.ts` in `./src/artifacts`. Read more on the [compiling page](../compiling_contracts/how_to_compile_contract.md).

Now you can import it to easily deploy and interact with the contract.

Expand Down Expand Up @@ -84,7 +88,7 @@ Its arguments are `PXE` client and contract constructor arguments.

Additionally the `.send()` method can have a few optional arguments too, which are specified in an optional object:

- `portalContract?: EthAddress`: The L1 portal address to link the contract to. See the section on [Portals to learn more about them](./portals/main.md).
- `portalContract?: EthAddress`: The L1 portal address to link the contract to. See the section on [Portals to learn more about them](../writing_contracts/portals/portals.md).
- `contractAddressSalt?: Fr`: A salt which is one of the inputs when computing a contract address of the contract to be deployed.
By default is set to a random value.
Set it, if you need a deterministic contract address (same functionality as Ethereum's `CREATE2` opcode).
Expand Down
14 changes: 9 additions & 5 deletions docs/docs/developers/contracts/main.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import DocCardList from '@theme/DocCardList';
---
title: Smart Contracts
---

# Aztec.nr
This section is a collection of how-to guides and references for building smart contracts with Aztec.nr.

If you are looking for an overview of how smart contracts work, head to the [Concepts section](../../learn/concepts/smart_contracts/main.md).

## What is Aztec.nr?

**Aztec.nr** is a framework for writing Aztec smart contracts.

## Nomenclature

[**Noir**](https://noir-lang.org/) is a domain specific language for creating and verifying proofs. It's design choices are influenced heavily by Rust.
[**Noir**](https://noir-lang.org/) is a domain specific language for creating and verifying proofs. Its design choices are influenced heavily by Rust.

A **smart contract** is just a collection of persistent state variables, and a collection of functions which may edit those state variables.

Expand All @@ -20,7 +24,7 @@ An **Aztec smart contract** is a smart contract with **private** state variables

## Install aztec-nargo

To write an Aztec.nr contract, you need to the compiler, `aztec-nargo` which is installed when you install the sandbox. See install instructions [here](../cli/sandbox-reference.md).
To write an Aztec.nr contract, you need to the compiler, `aztec-nargo` which is installed when you install the sandbox. See install instructions [here](../sandbox/references/sandbox-reference.md).

:::info
For those coming from vanilla Noir, the version used for aztec.nr is tracked separately to nargo for vanilla Noir. Be sure to use `aztec-nargo` to compile your contracts.
Expand All @@ -44,7 +48,7 @@ There are a number of tools to make writing Aztec.nr contracts in Noir more plea

## Tutorials

See the [Token Contract tutorial](../tutorials/writing_token_contract.md) for more info on getting set up to write contracts.
See the [Private Voting tutorial](../tutorials/writing_private_voting_contract.md) for more info on getting set up to write contracts.

## Learn more

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ Note inclusion proves that a note existed (its hash was included in a note hash
| block_number | u32 | Block number for proving note's existence |
| context | PrivateContext | Private context |

`prove_note_inclusion` takes 2 parameters:
## prove_note_commitment_inclusion

A **commitment**, also referred to as a **note hash** is a public acknowledgment of the existence of a note without revealing the content of the note. You can learn more about how to compress a note to a note hash [here](../../../learn/concepts/storage/trees/main.md#example-note).

`prove_note_commitment_inclusion` takes 2 parameters:

| Name | Type | Description |
|-----------------|------------------------|-----------------------------------------------------|
Expand Down
Loading