Quickstart
In this guide, you will
- Set up the Aztec sandbox locally
- Install the Aztec CLI
- Use the CLI to deploy an example contract that comes with the sandbox
- Use the CLI to interact with the contract you just deployed
... in less than 10 minutes.
Prerequisites
- Node.js >= v18 (recommend installing with nvm)
- Docker and Docker Compose (Docker Desktop under WSL2 on windows)
Install the Sandbox
You can run the Sandbox using either Docker or npm. In this guide we will use Docker, but you can learn more about alternative installation methods here.
To install the latest Sandbox version, run:
/bin/bash -c "$(curl -fsSL 'https://sandbox.aztec.network')"
This will attempt to run the Sandbox on localhost:8080
, so you will have to make sure nothing else is running on that port or change the port defined in ./.aztec/docker-compose.yml
. Running the command again will overwrite any changes made to the docker-compose.yml
.
This command will also install the CLI if a node package version of the CLI isn't found locally.
Alternatively, you can run the sandbox as an npm package.
Deploy a contract using the CLI
The sandbox is preloaded with multiple accounts. Let's assign them to shell variables. Run the following in your terminal, so we can refer to the accounts as $ALICE and $BOB from now on:
The default accounts that come with sandbox will likely change over time. Save two of the "Initial accounts" that are printed in the terminal when you started the sandbox.
ALICE="0x29e53e3e43377c80c8a1e390ed90ddf1167f376c4c063844ec18f8a81516c1c0"
BOB="0x2b66c968c3ae3b827b6614719141be12667bad86f13b401c667d64a7c56d911c"
ALICE_PRIVATE_KEY="0x2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281"
Source code: /yarn-project/end-to-end/src/guides/up_quick_start.sh#L11-L15
Start by deploying a token contract. After it is deployed, we check that the deployment succeeded, and export the deployment address to use in future commands. For more detail on how the token contract works, see the token contract tutorial.
aztec-cli deploy \
TokenContractArtifact \
--salt 0 \
--args $ALICE
CONTRACT="0x18a018014978f3a6b8f69548fbfc5fded6b829b36becea24dd7f7ee34927dff7"
aztec-cli check-deploy --contract-address $CONTRACT
Source code: /yarn-project/end-to-end/src/guides/up_quick_start.sh#L17-L25
Note that the deployed contract address is exported, so we can use it as $CONTRACT
later on.
Call a contract with the CLI
Alice is set up as the contract admin and token minter in the _initialize
function. Let's get Alice some private tokens.
We need to export the SECRET
and SECRET_HASH
values in order to privately mint tokens. Private tokens are claimable by anyone with the pre-image to a provided hash, see more about how the token contract works in the token contract tutorial. After the tokens have been minted, the notes will have to added to the Private Execution Environment (PXE) to be consumed by private functions. Once added, Alice can claim them with the redeem_shield
function. After this, Alice should have 1000 tokens in their private balance.
SECRET="0x29bf6afaf29f61cbcf2a4fa7da97be481fb418dc08bdab5338839974beb7b49f"
SECRET_HASH="0x0921759afa747c9073f75df9688a17d271cef0d6ec51eacf70e112402c4db6cd"
MINT_PRIVATE_OUTPUT=$(aztec-cli send mint_private \
--args 1000 $SECRET_HASH \
--contract-artifact TokenContractArtifact \
--contract-address $CONTRACT \
--private-key $ALICE_PRIVATE_KEY)
MINT_PRIVATE_TX_HASH=$(echo "$MINT_PRIVATE_OUTPUT" | grep "Transaction hash:" | awk '{print $NF}')
aztec-cli add-note \
$ALICE $CONTRACT 5 $MINT_PRIVATE_TX_HASH \
--note 1000 $SECRET_HASH
aztec-cli send redeem_shield \
--args $ALICE 1000 $SECRET \
--contract-artifact TokenContractArtifact \
--contract-address $CONTRACT \
--private-key $ALICE_PRIVATE_KEY
Source code: /yarn-project/end-to-end/src/guides/up_quick_start.sh#L27-L48
We can have Alice privately transfer tokens to Bob. Only Alice and Bob will know what's happened. Here, we use Alice's private key to send a transaction to transfer tokens to Bob. Once they are transferred, we can verify that it worked as expected by checking Alice's and Bob's balances:
aztec-cli send transfer \
--args $ALICE $BOB 500 0 \
--contract-artifact TokenContractArtifact \
--contract-address $CONTRACT \
--private-key $ALICE_PRIVATE_KEY
aztec-cli call balance_of_private \
--args $ALICE \
--contract-artifact TokenContractArtifact \
--contract-address $CONTRACT
aztec-cli call balance_of_private \
--args $BOB \
--contract-artifact TokenContractArtifact \
--contract-address $CONTRACT
Source code: /yarn-project/end-to-end/src/guides/up_quick_start.sh#L57-L73
Alice and Bob should have 500 tokens.
Congratulations! You are all set up with the Aztec sandbox!
What's next?
To start writing your first Aztec.nr smart contract, go to the next page.
You can also dig more into the sandbox and CLI here.