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 send
ing 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
Name | Type |
---|---|
T | extends string |
ContractStorageLayout
Ƭ ContractStorageLayout<T
>: { [K in T]: FieldLayout }
Type representing the storage layout of a contract.
Type parameters
Name | Type |
---|---|
T | extends 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
Name | Type |
---|---|
TContract | extends ContractBase = Contract |
DeployedWaitOpts
Ƭ DeployedWaitOpts: WaitOpts
& { wallet?
: Wallet
}
Options related to waiting for a deployment tx.
ProfileResult
Ƭ ProfileResult: PrivateKernelProverProfileResult
& { returnValues
: any
}
The result of a profile() call.
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
Name | Type | Description |
---|---|---|
cancellable? | boolean | Whether the transaction can be cancelled. If true, an extra nullifier will be emitted: H(nonce, GENERATOR_INDEX__TX_NULLIFIER) |
estimateGas? | boolean | Whether 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? | FeeOptions | The fee options for the transaction. |
nonce? | Fr | Custom 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? | boolean | Wether 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
Name | Type | Description |
---|---|---|
from? | AztecAddress | The sender's Aztec address. |
gasSettings? | GasSettings | Gas settings for the simulation. |
skipTxValidation? | boolean | Simulate 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
Name | Type | Description |
---|---|---|
debug? | boolean | Whether to include information useful for debugging/testing in the receipt. |
dontThrowOnRevert? | boolean | Whether to accept a revert as a status code for the tx when waiting for it. If false, will throw if the tx reverts. |
ignoreDroppedReceiptsFor? | number | The amount of time to ignore TxStatus.DROPPED receipts (in seconds) due to the presumption that it is being propagated by the p2p network. Defaults to 5. |
interval? | number | The time interval (in seconds) between retries to fetch the transaction receipt. Defaults to 1. |
proven? | boolean | Whether to wait for the tx to be proven. |
provenTimeout? | number | The maximum time (in seconds) to wait for the transaction to be proven. Defaults to 600. |
timeout? | number | The maximum time (in seconds) to wait for the transaction to be mined. Defaults to 60. |
waitForNotesAvailable? | boolean | Whether to wait for the node to notify that the block in which this tx was mined is available to fetch notes from. 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