Skip to content

raven-house/aztec-starter

Β 
Β 

Repository files navigation

<<<<<<< HEAD

Raven Aztec bridge

=======

Aztec Starter

upstream/main

Sandbox

This repo is meant to be a starting point for learning to write Aztec contracts and tests on the Aztec sandbox (local development environment). It includes an example contract, useful commands in package.json and helpful scripts in ./scripts.

<<<<<<< HEAD You can find the Easy Private Voting contract in ./src/main.nr. A simple integration test is in ./src/test/e2e/index.test.ts.

Devnet

This repo connects to a locally running Aztec Sandbox by default, but can be configured to connect to the devnet by specifying AZTEC_ENV=devnet in a .env file or by prefixing a command e.g. AZTEC_ENV=devnet bun deploy.


======= You can find the Pod Racing Game contract in ./src/main.nr. A simple integration test is in ./src/test/e2e/index.test.ts.

The Pod Racing contract is a two-player competitive game where players allocate points across 5 tracks over multiple rounds. The game demonstrates Aztec's private state capabilities - round choices remain private until players reveal their final scores.

Devnet

This repo connects to a locally running Aztec Sandbox by default, but can be configured to connect to the devnet by specifying AZTEC_ENV=devnet in a .env file or by prefixing a command e.g. AZTEC_ENV=devnet yarn deploy.

GitHub Repo stars GitHub forks Build GitHub last commit License Discord Twitter Follow


πŸš€ Getting Started

Use Node.js version 22.15.0.

Start your codespace from the codespace dropdown.

Get the sandbox, aztec-cli, and other tooling with this command:

bash -i <(curl -s https://install.aztec.network)

Install the correct version of the toolkit with:

upstream/main

export VERSION=3.0.0-devnet.5
aztec-up && docker pull aztecprotocol/aztec:$VERSION && docker tag aztecprotocol/aztec:$VERSION aztecprotocol/aztec:latest

Environment Configuration

This project uses JSON configuration files to manage environment-specific settings:

  • config/sandbox.json - Configuration for local sandbox development
  • config/devnet.json - Configuration for devnet deployment

The system automatically loads the appropriate configuration file based on the ENV environment variable. If ENV is not set, it defaults to sandbox.

The configuration files contain network URLs, timeouts, and environment-specific settings. You can modify these files to customize your development environment.

Running on Sandbox (Local Development)

Start the sandbox with:

<<<<<<< HEAD
aztec start --local-network
=======
aztec start --sandbox
>>>>>>> upstream/main

Run scripts and tests with default sandbox configuration:

<<<<<<< HEAD
bun compile && bun codegen  # Compile contract and generate TS
bun deploy       # Deploy to sandbox
bun test         # Run tests on sandbox
=======
yarn compile && yarn codegen  # Compile contract and generate TS
yarn deploy       # Deploy to sandbox
yarn test         # Run tests on sandbox
>>>>>>> upstream/main

Running on Devnet

All scripts support a ::devnet suffix to automatically use devnet configuration:

<<<<<<< HEAD
bun deploy::devnet              # Deploy to devnet
bun test::devnet                # Run tests on devnet
bun deploy-account::devnet      # Deploy account to devnet
bun interaction-existing-contract::devnet  # Interact with devnet contracts
=======
yarn deploy::devnet              # Deploy to devnet
yarn test::devnet                # Run tests on devnet
yarn deploy-account::devnet      # Deploy account to devnet
yarn interaction-existing-contract::devnet  # Interact with devnet contracts
>>>>>>> upstream/main

The ::devnet suffix automatically sets ENV=devnet, loading configuration from config/devnet.json.


πŸ“¦ Install Packages

<<<<<<< HEAD
bun install
=======
yarn install
>>>>>>> upstream/main

πŸ— Compile

aztec-nargo compile

or

<<<<<<< HEAD
bun compile
=======
yarn compile
>>>>>>> upstream/main

πŸ”§ Codegen

Generate the contract artifact JSON and TypeScript interface:

<<<<<<< HEAD
bun codegen
=======
yarn codegen
>>>>>>> upstream/main

⚠️ Tests and scripts set up and run the Private Execution Environment (PXE) and store PXE data in the ./store directory. If you restart the sandbox, you will need to delete the ./store directory to avoid errors.

Transaction Profiling

Make sure the sandbox is running before profiling.

aztec start --sandbox

Then run an example contract deployment profile with:

<<<<<<< HEAD
bun profile
=======
yarn profile
>>>>>>> upstream/main

You can specify the bb binary path for faster native proving, e.g.

<<<<<<< HEAD
BB_BINARY_PATH="/home/user/.bb/bb" BB_WORKING_DIRECTORY="/tmp/bb" CRS_PATH="/tmp/bb" bun profile
=======
BB_BINARY_PATH="/home/user/.bb/bb" BB_WORKING_DIRECTORY="/tmp/bb" CRS_PATH="/tmp/bb" yarn profile
>>>>>>> upstream/main

See the demo-wallet for an example of how to fetch the appropriate bb binary (version and OS) in an application.

πŸ§ͺ Test

Make sure the sandbox is running before running tests.

aztec start --sandbox

Then test with:

<<<<<<< HEAD
bun test
=======
yarn test
>>>>>>> upstream/main

Testing will run the TypeScript tests defined in index.test.ts inside ./src/test/e2e, as well as the Aztec Testing eXecution Environment (TXE) tests defined in first.nr (imported in the contract file with mod test;).

Note: The Typescript tests spawn an instance of the sandbox to test against, and close it once the TS tests are complete.


Scripts

You can find a handful of scripts in the ./scripts folder.

  • ./scripts/deploy_account.ts is an example of how to deploy a schnorr account.
  • ./scripts/deploy_contract.ts is an example of how to deploy a contract.
  • ./scripts/fees.ts is an example of how to pay for a contract deployment using various fee payment methods.
  • ./scripts/multiple_wallet.ts is an example of how to deploy a contract from one wallet instance and interact with it from another.
  • ./scripts/profile_deploy.ts shows how to profile a transaction and print the results. <<<<<<< HEAD
  • ./scripts/interaction_existing_contract.ts demonstrates how to interact with an already deployed voting contract, including casting votes and checking vote counts. =======
  • ./scripts/interaction_existing_contract.ts demonstrates how to interact with an already deployed pod racing contract, including creating games.

upstream/main

  • ./scripts/get_block.ts is an example of how to retrieve and display block information from the Aztec node.

Utility Functions

The ./src/utils/ folder contains utility functions:

  • ./src/utils/create_account_from_env.ts provides functions to create Schnorr accounts from environment variables (SECRET, SIGNING_KEY, and SALT), useful for account management across different environments.
  • ./src/utils/setup_wallet.ts provides a function to set up and configure the TestWallet with proper configuration based on the environment.
  • ./src/utils/deploy_account.ts provides a function to deploy Schnorr accounts to the network with sponsored fee payment, including key generation and deployment verification.
  • ./src/utils/sponsored_fpc.ts provides functions to deploy and manage the SponsoredFPC (Fee Payment Contract) for handling sponsored transaction fees.
  • ./config/config.ts provides environment-aware configuration loading, automatically selecting the correct JSON config file based on the ENV variable.

❗ Error Resolution

⚠️ Tests and scripts set up and run the Private Execution Environment (PXE) and store PXE data in the ./store directory. If you restart the sandbox, you will need to delete the ./store directory to avoid errors.

πŸ”„ Update Node.js and Noir Dependencies

<<<<<<< HEAD
bun update
=======
yarn update
>>>>>>> upstream/main

πŸ”„ Update Contract

Get the contract code from the monorepo. The script will look at the versions defined in ./Nargo.toml and fetch that version of the code from the monorepo.

<<<<<<< HEAD
bun update
=======
yarn update
>>>>>>> upstream/main

You may need to update permissions with:

chmod +x .github/scripts/update_contract.sh

AI Agent Contributor Guide

This repository includes an AGENTS.md file with detailed instructions for setting up your environment, running tests, and creating pull requests. Please read it before contributing changes.

<<<<<<< HEAD

What is Anvil

Anvil is a fast local ethereum development node

Anvil is part of the Foundry suit and is installed alongside forge, cast and chisel.

anvil --fork-url <RPC_URL>

=======

πŸ’¬ Join the Community:

Forum Telegram Discord Twitter (X)

>>>>>>> upstream/main

About

A simple aztec contract + test to get started.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 68.6%
  • Noir 30.8%
  • Dockerfile 0.6%