Class Predicate<TData, TConfigurables>

Predicate provides methods to populate transaction data with predicate information and sending transactions with them.

Type Parameters

  • TData extends InputValue[] = InputValue[]
  • TConfigurables extends {
        [name: string]: unknown;
    } | undefined = {
        [name: string]: unknown;
    }

Hierarchy (view full)

Constructors

Properties

_connector?: FuelConnector

The connector for use with external wallets

_provider?: Provider

The provider used to interact with the network.

address: Address

The address associated with the account.

bytes: Uint8Array<ArrayBufferLike>
configurableConstants: undefined | TConfigurables
initialBytecode: Uint8Array<ArrayBufferLike>
interface: Interface
predicateData: TData = ...

Accessors

  • get provider(): Provider
  • The provider used to interact with the network.

    Returns Provider

    A Provider instance.

    FuelError if the provider is not set.

  • set provider(provider): void
  • Sets the provider for the account.

    Parameters

    Returns void

Methods

  • Assembles transactions for consolidating base asset coins into fewer UTXOs.

    This method splits the provided coins into batches and creates transaction requests to consolidate them. It calculates the necessary fee and sets up the transactions to be submitted either in parallel (default) or sequentially.

    Parameters

    Returns Promise<{
        submitAll: SubmitAllCallback;
        totalFeeCost: BN;
        txs: ScriptTransactionRequest[];
    }>

    An object containing the assembled transactions, the total fee cost, and a callback to submit all transactions.

  • Transfers multiple amounts of a token to multiple recipients.

    Parameters

    • transferParams: TransferParams[]

      An array of TransferParams objects representing the transfers to be made.

    • txParams: TxParamsType = {}

      Optional transaction parameters.

    Returns Promise<TransactionResponse>

    A promise that resolves to a TransactionResponse object representing the transaction result.

  • Changes the provider connection for the account.

    Parameters

    Returns Provider

    The updated Provider instance.

  • Consolidates base asset UTXOs into fewer, larger ones.

    Retrieves a limited number of base asset coins (as defined by Provider.RESOURCES_PAGE_SIZE_LIMIT), assembles consolidation transactions, and submits them to the network.

    Note: This method currently supports only the base asset.

    Parameters

    • params: ConsolidateCoins

      The parameters for coin consolidation, including the asset ID, mode, and output number.

    Returns Promise<SubmitAllCallbackResponse>

    A promise that resolves to the response of the submitted transactions.

    Will throw an error if the asset is not a base asset as non-base asset consolidation is not implemented.

  • A helper that creates a transfer transaction request and returns it.

    Parameters

    • destination: string | Address

      The address of the destination.

    • amount: BigNumberish

      The amount of coins to transfer.

    • OptionalassetId: BytesLike

      The asset ID of the coins to transfer (optional).

    • txParams: TxParamsType = {}

      The transaction parameters (optional).

    Returns Promise<ScriptTransactionRequest>

    A promise that resolves to the prepared transaction request.

  • Type Parameters

    Parameters

    • account: Account

      The account used to pay the deployment costs.

    Returns Promise<{
        blobId: string;
        waitForResult: (() => Promise<T>);
    }>

    The blobId and a waitForResult callback that returns the deployed predicate once the blob deployment transaction finishes.

    The returned loader predicate will have the same configurable constants as the original predicate which was used to generate the loader predicate.

  • Generates an array of fake resources based on the provided coins.

    Parameters

    • coins: FakeResources[]

      An array of FakeResources objects representing the coins.

    Returns Resource[]

    An array of Resource objects with generated properties.

  • Retrieves the balance of the account for the given asset.

    Parameters

    • OptionalassetId: BytesLike

      The asset ID to check the balance for (optional).

    Returns Promise<BN>

    A promise that resolves to the balance amount.

  • Retrieves coins owned by the account.

    Parameters

    • OptionalassetId: BytesLike

      The asset ID of the coins to retrieve (optional).

    • OptionalpaginationArgs: CursorPaginationArgs

    Returns Promise<GetCoinsResponse>

    A promise that resolves to an array of Coins.

  • Retrieves messages owned by the account.

    Parameters

    • OptionalpaginationArgs: CursorPaginationArgs

    Returns Promise<GetMessagesResponse>

    A promise that resolves to an array of Messages.

  • Retrieves the properly encoded predicate data.

    Returns Uint8Array<ArrayBufferLike>

    A Uint8Array containing the encoded predicate data. If no predicate data is available, returns an empty Uint8Array.

  • Retrieves resources satisfying the spend query for the account.

    Parameters

    Returns Promise<Resource[]>

    A promise that resolves to an array of Resources.

  • Populates the transaction data with predicate data.

    Type Parameters

    Parameters

    Returns T

    The transaction request with predicate data.

  • Prepares a function to submit all transactions either sequentially or in parallel.

    Parameters

    Returns SubmitAllCallback

    A callback that, when called, submits all transactions and returns their results and any errors encountered.

  • Sets the predicate data.

    Parameters

    • data: TData

      The data to be set for the predicate.

    Returns void

  • Signs a transaction from the account via the connector..

    Parameters

    Returns Promise<string>

    A promise that resolves to the signature of the transaction.

  • Simulates a transaction with the populated predicate data.

    Parameters

    Returns Promise<CallResult>

    A promise that resolves to the call result.

  • Creates a new Predicate instance from an existing Predicate instance.

    Parameters

    Returns Predicate<TData, TConfigurables>

    A new Predicate instance with the same bytecode, ABI and provider but with the ability to set the data and configurable constants.

  • Transfers coins to a destination address.

    Parameters

    • destination: string | Address

      The address of the destination.

    • amount: BigNumberish

      The amount of coins to transfer.

    • OptionalassetId: BytesLike

      The asset ID of the coins to transfer (optional).

    • txParams: TxParamsType = {}

      The transaction parameters (optional).

    Returns Promise<TransactionResponse>

    A promise that resolves to the transaction response.

  • Transfers coins to a contract address.

    Parameters

    • contractId: string | Address

      The address of the contract.

    • amount: BigNumberish

      The amount of coins to transfer.

    • assetId: BytesLike

      The asset ID of the coins to transfer (optional).

    • txParams: TxParamsType = {}

      The transaction parameters (optional).

    Returns Promise<TransactionResponse>

    A promise that resolves to the transaction response.