Skip to main content

Module: contract

The contract module provides utilities for deploying and interacting with contracts, based on a Wallet instance and a compiled artifact. Refer to the account module for how to obtain a valid Wallet instance, and to the Compiling contracts section of the documentation for how to generate an artifact out of your Noir source code.

The Contract class is the main class in this module, and provides static methods for deploying a contract or interacting with an already deployed one. The methods property of the contract instance provides access to private, public, and simulate methods, that can be invoked in a transaction via send(), or can be queried via simulate().

const contract = await Contract.deploy(wallet, MyContractArtifact, [...constructorArgs]).send().deployed();
console.log(`Contract deployed at ${contract.address}`);
const contract = await Contract.at(address, MyContractArtifact, wallet);
await contract.methods.mint(1000, owner).send().wait();
console.log(`Total supply is now ${await contract.methods.totalSupply().simulate()}`);

The result of calling a method in a contract instance, such as contract.methods.mint(1000, owner) in the example, is a ContractFunctionInteraction instance. Usually this will be just sent as a transaction to the network via the send method, but you can also simulate it without sending, or obtaining the request for aggregating into a BatchCall.

The result of sending a transaction is a SentTx object, from which you can get the transaction hash, or simply wait until the transaction is mined and the local PXE Service has synchronized its changes.

Remarks

If you are using typescript, consider using the autogenerated type-safe interfaces for interacting with your contracts.

Classes

Type Aliases

ContractMethod

Ƭ ContractMethod: (...args: any[]) => ContractFunctionInteraction & { selector: FunctionSelector }

Type representing a contract method that returns a ContractFunctionInteraction instance and has a readonly 'selector' property of type Buffer. Takes any number of arguments.


ContractNotes

Ƭ ContractNotes<T>: { [K in T]: ContractNote }

Type representing the notes used in a contract.

Type parameters

NameType
Textends string

ContractStorageLayout

Ƭ ContractStorageLayout<T>: { [K in T]: FieldLayout }

Type representing the storage layout of a contract.

Type parameters

NameType
Textends string

DeployOptions

Ƭ DeployOptions: { contractAddressSalt?: Fr ; skipClassRegistration?: boolean ; skipInitialization?: boolean ; skipPublicDeployment?: boolean ; universalDeploy?: boolean } & SendMethodOptions

Options for deploying a contract on the Aztec network. Allows specifying a contract address salt, and additional send method options.


DeployTxReceipt

Ƭ DeployTxReceipt<TContract>: FieldsOf<TxReceipt> & { contract: TContract }

Extends a transaction receipt with a contract instance that represents the newly deployed contract.

Type parameters

NameType
TContractextends ContractBase = Contract

DeployedWaitOpts

Ƭ DeployedWaitOpts: WaitOpts & { wallet?: Wallet }

Options related to waiting for a deployment tx.


SendMethodOptions

Ƭ SendMethodOptions: Object

Represents options for calling a (constrained) function in a contract. Allows the user to specify the sender address and nonce for a transaction.

Type declaration

NameTypeDescription
cancellable?booleanWhether the transaction can be cancelled. If true, an extra nullifier will be emitted: H(nonce, GENERATOR_INDEX__TX_NULLIFIER)
estimateGas?booleanWhether to run an initial simulation of the tx with high gas limit to figure out actual gas settings (will default to true later down the road).
fee?FeeOptionsThe fee options for the transaction.
nonce?FrCustom nonce to inject into the app payload of the transaction. Useful when trying to cancel an ongoing transaction by creating a new one with a higher fee
skipPublicSimulation?booleanWether to skip the simulation of the public part of the transaction.

SimulateMethodOptions

Ƭ SimulateMethodOptions: Object

Represents the options for simulating a contract function interaction. Allows specifying the address from which the view method should be called. Disregarded for simulation of public functions

Type declaration

NameTypeDescription
from?AztecAddressThe sender's Aztec address.
gasSettings?GasSettingsGas settings for the simulation.
skipTxValidation?booleanSimulate without checking for the validity of the resulting transaction, e.g. whether it emits any existing nullifiers.

WaitOpts

Ƭ WaitOpts: Object

Options related to waiting for a tx.

Type declaration

NameTypeDescription
debug?booleanWhether to include information useful for debugging/testing in the receipt.
dontThrowOnRevert?booleanWhether to accept a revert as a status code for the tx when waiting for it. If false, will throw if the tx reverts.
interval?numberThe time interval (in seconds) between retries to fetch the transaction receipt. Defaults to 1.
proven?booleanWhether to wait for the tx to be proven.
provenTimeout?numberThe maximum time (in seconds) to wait for the transaction to be proven. Defaults to 600.
timeout?numberThe maximum time (in seconds) to wait for the transaction to be mined. Defaults to 60.
waitForNotesSync?booleanWhether to wait for the PXE Service to sync all notes up to the block in which this tx was mined. If false, then any queries that depend on state set by this transaction may return stale data. Defaults to true.

Variables

DefaultWaitOpts

Const DefaultWaitOpts: WaitOpts