Skip to main content

How to setup a new contract project


This guide explains the set up required to write a contract using the library.

Prerequisite reading

If you haven't read about, we recommend going there first.


Aztec Sandbox

You need to setup the Aztec sandbox.

Setup for contracts

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

  1. Next, create an Aztec contract project using aztec-nargo by running the following in the terminal from the contracts folder
cd contracts
aztec-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 file (the file where our contract will reside) at example_contract/src/

Your folder should look like:

| |--example_contract
| | |--src
| | | |
| | |--Nargo.toml
| |--index.ts

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

  1. Finally, add relevant aztec-nr dependencies that you might use such as, value_note and safe_math libraries.

Open Nargo.toml that is in the contracts/example_contract folder, and add the dependency section as follows

name = "example_contract"
authors = [""]
compiler_version = ">=0.18.0"
type = "contract"

# Framework import
aztec = { git="", tag="aztec-packages-v0.24.0", directory="noir-projects/aztec-nr/aztec" }

# Utility dependencies
value_note = { git="", tag="aztec-packages-v0.24.0", directory="noir-projects/aztec-nr/value-note"}
safe_math = { git="", tag="aztec-packages-v0.24.0", directory="noir-projects/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