TransactionWorker provides a simple framework for receiving payloads to be processed.

Once one start() the process and pushes a new transaction, the worker acquires the current account's next sequence number (by using the AccountSequenceNumber class), generates a signed transaction and pushes an async submission process into the outstandingTransactions queue. At the same time, the worker processes transactions by reading the outstandingTransactions queue and submits the next transaction to chain, it

  1. waits for resolution of the submission process or get pre-execution validation error and 2) waits for the resolution of the execution process or get an execution error. The worker fires events for any submission and/or execution success and/or failure.

Hierarchy (view full)

Constructors

  • Initializes a new instance of the class, providing a framework for receiving payloads to be processed.

    Parameters

    • aptosConfig: AptosConfig

      A configuration object for Aptos.

    • account: Account

      The account that will be used for sending transactions.

    • maxWaitTime: number = 30

      The maximum wait time to wait before re-syncing the sequence number to the current on-chain state, default is 30 seconds.

    • maximumInFlight: number = 100

      The maximum number of transactions that can be submitted per account, default is 100.

    • sleepTime: number = 10

      The time to wait in seconds before re-evaluating if the maximum number of transactions are in flight, default is 10 seconds.

    Returns TransactionWorker

Events

  • Reads the outstanding transaction queue and submits the transactions to the chain. This function processes each transaction, checking their status and emitting events based on whether they were successfully sent or failed.

    Returns Promise<void>

    Throws an error if the process execution fails. TransactionWorkerEventsEnum.TransactionSent - Emitted when a transaction has been successfully committed to the chain. TransactionWorkerEventsEnum.TransactionSendFailed - Emitted when a transaction fails to commit, along with the error reason. TransactionWorkerEventsEnum.ExecutionFinish - Emitted when the execution of transactions is complete.

Methods

  • Generates a signed transaction that can be submitted to the chain.

    Parameters

    • account: Account

      An Aptos account used as the sender of the transaction.

    • sequenceNumber: bigint

      A sequence number the transaction will be generated with.

    Returns Promise<undefined | SimpleTransaction>

    A signed transaction object or undefined if the transaction queue is empty.

  • Return the number of listeners listening to a given event.

    Parameters

    Returns number

  • Remove all listeners, or those of the specified event.

    Parameters

    • Optionalevent: keyof TransactionWorkerEvents

    Returns this

  • Starts transaction submission and processing by executing tasks from the queue until it is cancelled.

    Returns Promise<void>

    Throws an error if unable to start transaction batching.

  • Submits the next transaction for the account by generating it with the current sequence number and adding it to the outstanding transaction queue for processing. This function continues to submit transactions until there are no more to process.

    Returns Promise<void>

    Throws an error if the transaction submission fails.

Properties

account: Account
accountSequnceNumber: AccountSequenceNumber
aptosConfig: AptosConfig
executedTransactions: [string, bigint, any][] = []

transactions that have been committed to chain

outstandingTransactions: AsyncQueue<[Promise<PendingTransactionResponse>, bigint]> = ...

signed transactions waiting to be submitted

sentTransactions: [string, bigint, any][] = []

transactions that have been submitted to chain

started: boolean
taskQueue: AsyncQueue<(() => Promise<void>)> = ...

transactions payloads waiting to be generated and signed

TODO support entry function payload from ABI builder

prefixed: string | boolean