Skip to content

Commit

Permalink
feat(docs): set up noir contracts in getting-started (#1770)
Browse files Browse the repository at this point in the history
Fix #1699 - there was no set-up guide for noir contracts on getting
started

Don't see a point to explain how to write, compile or deploy when these
are already covered in multiple other places

---------

Co-authored-by: Maddiaa <47148561+Maddiaa0@users.noreply.github.com>
Co-authored-by: Lasse Herskind <16536249+LHerskind@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 5, 2023
1 parent c5d95c8 commit 33eb99d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 50 deletions.
2 changes: 1 addition & 1 deletion docs/docs/about_aztec/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Contributors to Aztec uphold many of the values of the Ethereum community -- bui

Noir is a domain specific programming language for writing zero knowledge circuits. On Aztec a smart contract is a collection of circuits that developers write using Noir.

You can find more information and resources for learning about Noir on [this page](../dev_docs/getting_started/noir).
You can find more information and resources for learning about Noir smart contracts on [this page](../dev_docs/getting_started/noir_contracts.md).

## Cryptography

Expand Down
47 changes: 0 additions & 47 deletions docs/docs/dev_docs/getting_started/noir.md

This file was deleted.

79 changes: 79 additions & 0 deletions docs/docs/dev_docs/getting_started/noir_contracts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
title: Aztec.nr Contracts
---

## Introduction

This guide explains the set up required to write a contract using the Aztec.nr library; then deploy it to the sandbox. Aztec.nr is a library on top of [Noir](https://noir-lang.org/) that can be used to write smart contracts for Aztec. Since Noir files use the `.nr` extension, we are calling this library "Aztec.nr".

:::info Prerequisite reading
If you haven't read [Aztec Sandbox](./sandbox.md), we recommend going there first.
:::

### Dependencies
#### `nargo`
Nargo is Noir's build tool. On your terminal, run:
```bash
curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash
noirup -v aztec
```
This ensures you are on the aztec branch of nargo.
#### Aztec Sandbox
You need to setup the [aztec sandbox](./sandbox.md)

<!-- TODO([#1056](https://github.com/AztecProtocol/aztec-packages/issues/1056)): Add a step for the starter kit -->

## Set up for aztec.nr contracts
1. Inside the yarn project you created from the [Sandbox](./sandbox.md) page, create a sub-folder where the contracts will reside.
```bash
mkdir contracts
```

All contract projects will reside within this folder. Note that contracts don't actually have to live here and this is just a style choice.

2. Next, create a noir project using nargo by running the following in the terminal from the `contracts` folder
```bash
cd contracts
nargo new example_contract
```

This creates a noir project with a Nargo.toml (which is the manifest file of the project). This file is found at `example_contract/src/main.nr`, where we will write our contract.

Your folder should look like:
```
.
|-contracts
| |--example_contract
| | |--src
| | | |--main.nr
|-src
| |--index.ts
```

Before writing the contracts, we must add the aztec.nr library. This adds smart contract utility functions for interacting with the Aztec network.

3. Add aztec.nr library as a dependency to your noir project. Open Nargo.toml that is in the `contracts/example_contract` folder, and add the dependency section as follows:
```
[package]
name = "example_contract"
authors = [""]
compiler_version = "0.1"
type = "contract"
[dependencies]
aztec = { git="https://github.com/AztecProtocol/aztec-packages", tag="master", directory="yarn-project/noir-libs/noir-aztec" }
```

You are now ready to write your own contracts!

You can replace the content of the generated file `example_contract/src/main.nr` with your contract code.

## Next Steps
You can learn more about writing contracts from the [Contracts section](../contracts/main.md).
For now you can use the [PrivateToken contract example here](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr).

After writing the contract, you have to compile it. Details can be found [here](../contracts/compiling.md).

After compiling, you can deploy your contract to the Aztec network. Relevant instructions and explainations can be found [here](../contracts/deploying.md).

Thereafter, you can interact with the contracts similar to how it was shown in the the [Creating and submitting transactions section on the Sandbox page](./sandbox.md#creating-and-submitting-transactions).
7 changes: 6 additions & 1 deletion docs/docs/dev_docs/getting_started/sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Add a `tsconfig.json` file into the project root, here is an example:
"skipLibCheck": true
},
"references": [],
"include": ["src"]
"include": ["src", "src/*.json"]
}
```

Expand Down Expand Up @@ -349,3 +349,8 @@ Our complete output should now be:
```

That's it! We have successfully deployed a private token contract to an instance of the Aztec network and mined private state-transitioning transactions. We have also queried the resulting state all via the interfaces provided by the contract.

## Next Steps
Here we showed how to interact with the sandbox, but didn't go into details on how to write your own contract or any relevant setup needed for it.

You can find details on setting up [here](./noir_contracts.md) and refer to the [Contracts section](../contracts/main.md) on syntax, compiling, deploying and interacting with how to start writing contracts.
2 changes: 1 addition & 1 deletion docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ const sidebars = {
id: "dev_docs/getting_started/main",
},
items: [
"dev_docs/getting_started/noir",
"dev_docs/getting_started/sandbox",
"dev_docs/getting_started/noir_contracts",
"dev_docs/getting_started/cli",
],
},
Expand Down

0 comments on commit 33eb99d

Please sign in to comment.