Here you will find a reference to the commands available in the Aztec CLI.
This command will install the Aztec CLI as a dev dependency in your npm project.
npm install --save-dev @aztec/cli
You can install the CLI globally, but it is recommended that you install the CLI as a local dependency in your project. This will make it easier to keep the CLI version in sync with the sandbox version.
The CLI will be installed automatically via Docker if it is not already found locally, by running the command to install and start the sandbox, instructions here.
The CLI comes with an update command.
npx @aztec/cli@latest update . --contract src/contract1 --contract src/contract2
This command does a few things to manage updates:
- If you installed the CLI globally via a node package manager, it updates to the specified version. Defaults to latest.
- It looks for a
package.jsonand updates all
@aztec/dependencies to the versions the sandbox expects.
- It looks for
--contractpaths specified and updates all
aztec.nrdependencies to the versions the sandbox expects.
- It outputs the changes.
The sandbox must be running for the update command to work unless there the project defines
@aztec/aztec-sandbox as a dependency, in which case the command will compare against the version listed in
If you installed the CLI via Docker (with the sandbox install Docker command), the
aztec-cli update command won't work. You can update the CLI it by running the command again.
You can find more information about compiling contracts on this page.
The first thing we want to do is create a couple of accounts. We will use the
create-account command which will generate a new private key for us, register the account on the sandbox, and deploy a simple account contract which uses a single key for privacy and authentication:
% aztec-cli create-account
Created new account:
Public key: 0x02d18745eadddd496be95274367ee2cbf0bf667b81373fb6bed715c18814a09022907c273ec1c469fcc678738bd8efc3e9053fe1acbb11fa32da0d6881a1370e
Private key: 0x2aba9e7de7075deee3e3f4ad1e47749f985f0f72543ed91063cc97a40d851f1e
Partial address: 0x72bf7c9537875b0af267b4a8c497927e251f5988af6e30527feb16299042ed
Once the account is set up, the CLI returns the resulting address, its privacy key, and partial address. You can read more about these here.
Save the Address and Private key as environment variables. We will be using them later.
export ADDRESS=<Address printed when you run the command>
export PRIVATE_KEY=<Private key printed when you run the command>
Alternatively, we can also manually generate a private key and use it for creating the account, either via a
-k option or by setting the
PRIVATE_KEY environment variable.
% aztec-cli generate-private-key
Private Key: 0x12684562c8676e66be100878434b01286a757dea468233f818b906f66fb34984
Public Key: 0x1003732857c052c1d6af4dd74b5631863a056c90a586c4e3ea6d94782ee712d317cdb713ed1ba02d3df0ac2b581d269490f9e24916c1b677c7259444aa0ad66b
% aztec-cli create-account --private-key 0x12684562c8676e66be100878434b01286a757dea468233f818b906f66fb34984
Created new account:
Public key: 0x1003732857c052c1d6af4dd74b5631863a056c90a586c4e3ea6d94782ee712d317cdb713ed1ba02d3df0ac2b581d269490f9e24916c1b677c7259444aa0ad66b
Partial address: 0x01e5e7b2abbfb98a93b7549ae80faa6886f8ea8e8f412416fb330b565fd2b4ed
For all commands that require a user's private key, the CLI will look for the
PRIVATE_KEY environment variable in absence of an optional argument.
Let's double check that the accounts have been registered with the sandbox using the
% aztec-cli get-accounts
Public Key: 0x27c20118733174347b8082f578a7d8fb84b3ad38be293715eee8119ee5cd8a6d0d6b7d8124b37359663e75bcd2756f544a93b821a06f8e33fba68cc8029794d9
Partial Address: 0x1c6484e22441e5ca43bba53495d0cdc911da299150fde1191bcb330b64716ff9
Public Key: 0x08145e8e8d46f51cda8d4c9cad81920236366abeafb8d387002bad879a3e87a81570b04ac829e4c007141d856d5a36d3b9c464e0f3c1c99cdbadaa6bb93f3257
Partial Address: 0x1833e53112953e6830a230cfc2895caed604f6395bbfafa730da26c5bf53c0a9
Public Key: 0x13e6151ea8e7386a5e7c4c5221047bf73d0b1b7a2ad14d22b7f73e57c1fa00c614bc6da69da1b581b09ee6cdc195e5d58ae4dce01b63bbb744e58f03855a94dd
Partial Address: 0x30034aaf5d78821effa4827a132357110a49a4f37b6e384d884e233595bcf342
Public Key: 0x240845f1179e3fbaa6ce587d44722b3452bbdaa11deb29553196b23534985d432b746bcf2f0e7046eb13f0ca0c4fedd027dc80b64384f50d6a14ad248faa941a
Partial Address: 0x03834845fc488d1454f195abe7d52b3393f6902eee080c90cd694c63572f7160
You will see a that a number of accounts exist that we did not create. The Sandbox initializes itself with 3 default accounts. Save one of the printed accounts (not the one that you generated above) in an environment variable. We will use it later.
export ADDRESS2=<Account address printed by the above command>
Deploying a Token Contract
We will now deploy a token contract using the
deploy command, and set an address of the admin via a constructor argument. You can find the contract we are deploying here (or write it for yourself in this tutorial!)
Make sure to replace this address with one of the two you created earlier.
% aztec-cli deploy TokenContractArtifact --args $ADDRESS
Contract deployed at 0x1ae8eea0dc265fb7f160dae62cc8912686d8a9ed78e821fbdd8bcedc54c06d0f
Save the contract address as an environment variable. We will use it later.
export CONTRACT_ADDRESS=<Your new contract address>
--args- Arguments to the constructor of the contract. In this case we have set an address as admin.
The CLI tells us that the contract was successfully deployed. We can use the
check-deploy command to verify that a contract has been successfully deployed to that address:
% aztec-cli check-deploy --contract-address $CONTRACT_ADDRESS
Contract found at 0x1ae8eea0dc265fb7f160dae62cc8912686d8a9ed78e821fbdd8bcedc54c06d0f
Sending a Transaction
We can now send a transaction to the network. We will mint funds in the public domain.
To form and submit the transaction we will use the
send command of
send command expect the function name as the first unnamed argument and the following named arguments:
--args- The list of arguments to the function call.
--contract-artifact- The artifact of the contract to call.
--contract-address- The deployed address of the contract to call.
--private-key- The private key of the sender.
% aztec-cli send mint_public \
--args $ADDRESS 543 \
--contract-artifact TokenContractArtifact \
--contract-address $CONTRACT_ADDRESS \
Transaction has been mined
Transaction hash: 15c5a8e58d5f895c7e3017a706efbad693635e01f67345fa60a64a340d83c78c
Block number: 5
Block hash: 163697608599543b2bee9652f543938683e4cdd0f94ac506e5764d8b908d43d4
We called the
mint_public function and provided it with the 2 arguments it expects: the recipient's address and the amount to be minted. Make sure to replace all addresses in this command with yours.
The command output tells us the details of the transaction such as its hash and status. We can use this hash to query the receipt of the transaction at a later time:
% aztec-cli get-tx-receipt 15c5a8e58d5f895c7e3017a706efbad693635e01f67345fa60a64a340d83c78c
Calling an Unconstrained (View) Function
Now that the
mint_public tx has been settled we can call the
balance_of_public unconstrained function:
% aztec-cli call balance_of_public -a $ADDRESS -c TokenContractArtifact -ca $CONTRACT_ADDRESS
View result: 543n
call command calls a read-only method on a contract, one that will not generate a transaction to be sent to the network. The arguments here are:
--args- The address for which we want to retrieve the balance.
--contract-artifact- The artifact of the contract we are calling.
--contract-address- The address of the deployed contract
As you can see from the result, this address has a public balance of 543, as expected.