Setup
Introduction
This guide explains the set up required to write a contract using the Aztec.nr library.
If you haven't read about Aztec.nr, we recommend going there first.
Dependencies
nargo
Nargo is Noir's build tool. On your terminal, run:
curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash
noirup -v v0.18.0-aztec.5
Aztec Sandbox
You need to setup the Aztec sandbox.
Set up for aztec.nr contracts
- Inside the yarn project you created from the Sandbox page, create a sub-folder where the contracts will reside.
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.
- Next, create a noir project using nargo by running the following in the terminal from the
contracts
folder
cd contracts
nargo new --contract example_contract
This creates example_contract
directory within contracts which is a noir project with:
- a Nargo.toml (which is the manifest file of the project) at
example_contract/Nargo.toml
. - a main.nr file (the file where our contract will reside) at
example_contract/src/main.nr
.
Your folder should look like:
.
|-contracts
| |--example_contract
| | |--src
| | | |--main.nr
| | |--Nargo.toml
|-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.
- Finally, add relevant aztec-nr dependencies that you might use such as
aztec.nr
,value_note
andsafe_math
libraries.
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.18.0"
type = "contract"
[dependencies]
# Framework import
aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="aztec-packages-v0.16.1", directory="yarn-project/aztec-nr/aztec" }
# Utility dependencies
value_note = { git="https://github.com/AztecProtocol/aztec-packages/", tag="aztec-packages-v0.16.1", directory="yarn-project/aztec-nr/value-note"}
safe_math = { git="https://github.com/AztecProtocol/aztec-packages/", tag="aztec-packages-v0.16.1", directory="yarn-project/aztec-nr/safe-math"}
Note: currently the dependency name MUST be aztec
. The framework expects this namespace to be available when compiling into contracts. This limitation may be removed in the future.
You are now ready to write your own contracts!
Next Steps
- Read up about how to write a contract OR
- Follow a tutorial