Skip to main content

Class: Contract

contract.Contract

The Contract class represents a contract and provides utility methods for interacting with it. It enables the creation of ContractFunctionInteraction instances for each function in the contract's ABI, allowing users to call or send transactions to these functions. Additionally, the Contract class can be used to attach the contract instance to a deployed contract on-chain through the PXE, which facilitates interaction with Aztec's privacy protocol.

Hierarchy

Constructors

constructor

new Contract(instance, artifact, wallet): Contract

Parameters

NameTypeDescription
instanceContractInstanceWithAddressThe deployed contract instance definition.
artifactContractArtifactThe Application Binary Interface for the contract.
walletWalletThe wallet used for interacting with this contract.

Returns

Contract

Inherited from

ContractBase.constructor

Properties

artifact

Readonly artifact: ContractArtifact

The Application Binary Interface for the contract.

Inherited from

ContractBase.artifact


instance

Readonly instance: ContractInstanceWithAddress

The deployed contract instance definition.

Inherited from

ContractBase.instance


methods

methods: Object = {}

An object containing contract methods mapped to their respective names.

Index signature

▪ [name: string]: ContractMethod

Inherited from

ContractBase.methods


wallet

Protected wallet: Wallet

The wallet used for interacting with this contract.

Inherited from

ContractBase.wallet

Accessors

address

get address(): AztecAddress

Address of the contract.

Returns

AztecAddress

Inherited from

ContractBase.address


partialAddress

get partialAddress(): Fr

Partial address of the contract.

Returns

Fr

Inherited from

ContractBase.partialAddress

Methods

withWallet

withWallet(wallet): this

Creates a new instance of the contract wrapper attached to a different wallet.

Parameters

NameTypeDescription
walletWalletWallet to use for sending txs.

Returns

this

A new contract instance.

Inherited from

ContractBase.withWallet


at

at(address, artifact, wallet): Promise<Contract>

Creates a contract instance.

Parameters

NameTypeDescription
addressAztecAddressThe deployed contract's address.
artifactContractArtifactBuild artifact of the contract.
walletWalletThe wallet to use when interacting with the contract.

Returns

Promise<Contract>

A promise that resolves to a new Contract instance.


deploy

deploy(wallet, artifact, args, constructorName?): DeployMethod<Contract>

Creates a tx to deploy a new instance of a contract.

Parameters

NameTypeDescription
walletWalletThe wallet for executing the deployment.
artifactContractArtifactBuild artifact of the contract to deploy
argsany[]Arguments for the constructor.
constructorName?stringThe name of the constructor function to call.

Returns

DeployMethod<Contract>


deployWithPublicKeysHash

deployWithPublicKeysHash(publicKeysHash, wallet, artifact, args, constructorName?): DeployMethod<Contract>

Creates a tx to deploy a new instance of a contract using the specified public keys hash to derive the address.

Parameters

NameTypeDescription
publicKeysHashFrHash of public keys to use for deriving the address.
walletWalletThe wallet for executing the deployment.
artifactContractArtifactBuild artifact of the contract.
argsany[]Arguments for the constructor.
constructorName?stringThe name of the constructor function to call.

Returns

DeployMethod<Contract>