Skip to main content

Deploying contracts

Once you have compiled your contracts you can proceed to deploying them using the aztec-cli or using aztec.js which is a Typescript client to interact with the sandbox.

Prerequisites

Deploy

Contracts can be deployed using the aztec-cli or using the aztec.js library.

aztec-cli deploy /path/to/contract/artifact.json

Deploy Arguments

There are several optional arguments that can be passed:

aztec-cli deploy takes 1 mandatory argument which is the path to the contract artifact file in a JSON format (e.g. contracts/target/PrivateToken.json). Alternatively you can pass the name of an example contract as exported by @aztec/noir-contracts.js (run aztec-cli example-contracts to see the full list of contracts available).

The command also takes the following optional arguments:

  • -args <constructorArgs...> (default: []): Arguments to pass to the contract constructor.
  • --rpc-url <string> (default: http://localhost:8080): URL of the PXE to connect to.
  • --public-key <string> (default: undefined): Optional encryption public key for this contract. Set this only if this contract is expected to receive private notes (in such a case the public key is used during the note encryption).
  • --salt <string> (default: random value): Hexadecimal string used when computing the contract address of the contract being deployed. By default is set to a random value. Set it, if you need a deterministic contract address (same functionality as Ethereum's CREATE2 opcode).

Deploying token contract

To give you a more complete example we will deploy a Token contract whose artifacts are included in the @aztec/noir-contracts.js package.

The contract has admin as a constructor argument. We will deploy the contract with the aztec-cli and pass the admin address as an argument.

aztec-cli deploy TokenContractArtifact --args 0x147392a39e593189902458f4303bc6e0a39128c5a1c1612f76527a162d36d529

If everything went as expected you should see the following output (with a different address):

Contract deployed at 0x151de6120ae6628129ee852c5fc7bcbc8531055f76d4347cdc86003bbea96906

If we pass the salt as an argument:

aztec-cli deploy TokenContractArtifact --args 0x147392a39e593189902458f4303bc6e0a39128c5a1c1612f76527a162d36d529 --salt 0x123

the resulting address will be deterministic.

NOTE: You can try running the deployment with the same salt the second time in which case the transaction will fail because the address has been already deployed to.