@aptos-labs/ts-sdk - v3.1.1
    Preparing search index...

    Class AccountSequenceNumber

    Represents an account's sequence number management for transaction handling on the Aptos blockchain. This class provides methods to retrieve the next available sequence number, synchronize with the on-chain sequence number, and manage local sequence numbers while ensuring thread safety.

    The configuration settings for Aptos.

    The account associated with the sequence number.

    The maximum time to wait for a transaction to commit.

    The maximum number of transactions that can be in flight at once.

    The time to wait before retrying to get the sequence number.

    Index

    Implementation - Transactions

    • Creates an instance of the class with the specified configuration and account details. This constructor initializes the necessary parameters for managing Aptos transactions.

      Parameters

      • aptosConfig: AptosConfig

        The configuration settings for Aptos.

      • account: Account

        The account associated with the Aptos transactions.

      • maxWaitTime: number

        The maximum time to wait for a transaction to be processed, in milliseconds.

      • maximumInFlight: number

        The maximum number of transactions that can be in flight at the same time.

      • sleepTime: number

        The time to sleep between transaction checks, in milliseconds.

      Returns AccountSequenceNumber

    lock: boolean = false

    We want to guarantee that we preserve ordering of workers to requests.

    lock is used to try to prevent multiple coroutines from accessing a shared resource at the same time, which can result in race conditions and data inconsistency. This code actually doesn't do it though, since we aren't giving out a slot, it is still somewhat a race condition.

    The ideal solution is likely that each thread grabs the next number from an incremental integer. When they complete, they increment that number and that entity is able to enter the lock. That would guarantee ordering.

    • Initializes this account with the sequence number on chain.

      Returns Promise<void>

      A promise that resolves when the account has been initialized.

      Throws an error if the account information cannot be retrieved.

    • Returns the next available sequence number for this account. This function ensures that the sequence number is updated and synchronized, handling potential delays in transaction commits.

      Returns Promise<null | bigint>

      The next available sequence number.

    • Synchronizes the local sequence number with the sequence number on-chain for the specified account. This function polls the network until all submitted transactions have either been committed or until the maximum wait time has elapsed.

      Returns Promise<void>

      Throws an error if there is an issue synchronizing the account sequence number with the one on-chain.

    Properties

    account: Account
    aptosConfig: AptosConfig
    currentNumber: null | bigint = null
    lastUncommintedNumber: null | bigint = null
    maximumInFlight: number
    maxWaitTime: number
    sleepTime: number