Skip to content

Class: ContractFactory

@fuel-ts/contract.ContractFactory

ContractFactory provides utilities for deploying and configuring contracts.

Constructors

constructor

new ContractFactory(bytecode, abi, accountOrProvider?): ContractFactory

Create a ContractFactory instance.

Parameters

NameTypeDefault valueDescription
bytecodeBytesLikeundefinedThe bytecode of the contract.
abiJsonAbi | Interface<JsonAbi>undefinedThe contract's ABI (Application Binary Interface).
accountOrProvidernull | Provider | AccountnullAn account or provider to be associated with the factory.

Returns

ContractFactory

Defined in

contract-factory.ts:68

Properties

account

account: null | Account

Defined in

contract-factory.ts:59


bytecode

bytecode: BytesLike

Defined in

contract-factory.ts:56


interface

interface: Interface<JsonAbi>

Defined in

contract-factory.ts:57


provider

provider: null | Provider

Defined in

contract-factory.ts:58

Methods

blobTransactionRequest

blobTransactionRequest(options): BlobTransactionRequest

Create a blob transaction request, used for deploying contract chunks.

Parameters

NameTypeDescription
options{ bytecode: BytesLike } & { chunkSizeMultiplier?: number ; configurableConstants?: { [name: string]: unknown; } ; salt?: BytesLike ; stateRoot?: BytesLike ; storageSlots?: StorageSlot[] } & CreateTransactionRequestLikeoptions for creating a blob transaction request.

Returns

BlobTransactionRequest

a populated BlobTransactionRequest.

Defined in

contract-factory.ts:425


connect

connect(provider): ContractFactory

Connect the factory to a provider.

Parameters

NameTypeDescription
providerProviderThe provider to be associated with the factory.

Returns

ContractFactory

A new ContractFactory instance.

Defined in

contract-factory.ts:110


createTransactionRequest

createTransactionRequest(deployOptions?): Object

Create a transaction request to deploy a contract with the specified options.

Parameters

NameTypeDescription
deployOptions?{ chunkSizeMultiplier?: number ; configurableConstants?: { [name: string]: unknown; } ; salt?: BytesLike ; stateRoot?: BytesLike ; storageSlots?: StorageSlot[] } & CreateTransactionRequestLike & { bytecode?: BytesLike }Options for deploying the contract.

Returns

Object

The CreateTransactionRequest object for deploying the contract.

NameType
contractIdstring
transactionRequestCreateTransactionRequest

Defined in

contract-factory.ts:120


deploy

deploy<TContract>(deployOptions?): Promise<DeployContractResult<TContract>>

Deploy a contract of any length with the specified options.

Type parameters

NameType
TContractextends Contract = Contract

Parameters

NameTypeDescription
deployOptionsDeployContractOptionsOptions for deploying the contract.

Returns

Promise<DeployContractResult<TContract>>

A promise that resolves to the deployed contract instance.

Defined in

contract-factory.ts:195


deployAsBlobTx

deployAsBlobTx<TContract>(deployOptions?): Promise<DeployContractResult<TContract>>

Chunks and deploys a contract via a loader contract. Suitable for deploying contracts larger than the max contract size.

Type parameters

NameType
TContractextends Contract = Contract

Parameters

NameTypeDescription
deployOptionsDeployContractOptionsOptions for deploying the contract.

Returns

Promise<DeployContractResult<TContract>>

A promise that resolves to the deployed contract instance.

Defined in

contract-factory.ts:247


deployAsCreateTx

deployAsCreateTx<TContract>(deployOptions?): Promise<DeployContractResult<TContract>>

Deploy a contract with the specified options.

Type parameters

NameType
TContractextends Contract = Contract

Parameters

NameTypeDescription
deployOptionsDeployContractOptionsOptions for deploying the contract.

Returns

Promise<DeployContractResult<TContract>>

A promise that resolves to the deployed contract instance.

Defined in

contract-factory.ts:213


fundTransactionRequest

fundTransactionRequest(request, options?): Promise<TransactionRequest>

Takes a transaction request, estimates it and funds it.

Parameters

NameTypeDescription
requestTransactionRequestthe request to fund.
optionsDeployContractOptionsoptions for funding the request.

Returns

Promise<TransactionRequest>

a funded transaction request.

Defined in

contract-factory.ts:164


getAccount

getAccount(): Account

Returns

Account

Defined in

contract-factory.ts:395


getMaxChunkSize

getMaxChunkSize(deployOptions, chunkSizeMultiplier?): number

Get the maximum chunk size for deploying a contract by chunks.

Parameters

NameTypeDefault value
deployOptionsDeployContractOptionsundefined
chunkSizeMultipliernumberCHUNK_SIZE_MULTIPLIER

Returns

number

Defined in

contract-factory.ts:438


prepareDeploy

prepareDeploy(deployOptions): Promise<{ contractId: string ; transactionRequest: CreateTransactionRequest }>

Parameters

NameType
deployOptionsDeployContractOptions

Returns

Promise<{ contractId: string ; transactionRequest: CreateTransactionRequest }>

Defined in

contract-factory.ts:402


setConfigurableConstants

setConfigurableConstants(configurableConstants): void

Set configurable constants of the contract with the specified values.

Parameters

NameTypeDescription
configurableConstantsObjectAn object containing configurable names and their values.

Returns

void

Defined in

contract-factory.ts:358