Class TxHandler

This class is responsible for creating and signing transactions.

Hierarchy

  • TxHandler

Constructors

  • Parameters

    • props: {
          config?: TxHandlerConfig;
          confirmationOptions: ConfirmOptions;
          connection: Connection;
          opts?: {
              onSignedCb?: ((txSigs: SignedTxData[]) => void);
              preSignedCb?: (() => void);
              returnBlockHeightsWithSignedTxCallbackData?: boolean;
          };
          wallet: IWallet;
      }
      • Optional config?: TxHandlerConfig
      • confirmationOptions: ConfirmOptions
      • connection: Connection
      • Optional opts?: {
            onSignedCb?: ((txSigs: SignedTxData[]) => void);
            preSignedCb?: (() => void);
            returnBlockHeightsWithSignedTxCallbackData?: boolean;
        }
        • Optional onSignedCb?: ((txSigs: SignedTxData[]) => void)
        • Optional preSignedCb?: (() => void)
            • (): void
            • Returns void

        • Optional returnBlockHeightsWithSignedTxCallbackData?: boolean
      • wallet: IWallet

    Returns TxHandler

Properties

blockHashFetcher: BlockhashFetcher
blockHashToLastValidBlockHeightLookup: Record<string, number> = {}
blockhashCommitment: Commitment = DEFAULT_CONFIRMATION_OPTS.commitment
confirmationOptions: ConfirmOptions
connection: Connection
onSignedCb?: ((txSigs: SignedTxData[]) => void)

Type declaration

preSignedCb?: (() => void)

Type declaration

    • (): void
    • Returns void

returnBlockHeightsWithSignedTxCallbackData: boolean = false
wallet: IWallet

Methods

  • Parameters

    • recentBlockhash: Readonly<{
          blockhash: string;
          lastValidBlockHeight: number;
      }>
    • message: Message | MessageV0

    Returns VersionedTransaction

  • Parameters

    • hashAndExpiry: Readonly<{
          blockhash: string;
          lastValidBlockHeight: number;
      }>

    Returns void

  • Builds and signs transactions from a given array of instructions for multiple transactions.

    Returns

    Type Parameters

    • T extends Record<string, TransactionInstruction | TransactionInstruction[]>

    Parameters

    • props: Omit<TxBuildingProps, "instructions"> & {
          instructionsMap: T;
      }

    Returns Promise<{
        signedTxData: SignedTxData[];
        signedTxMap: Record<string, Transaction>;
    } | {
        signedTxData: SignedTxData[];
        signedTxMap: MappedRecord<T, Transaction | VersionedTransaction>;
    }>

  • Accepts multiple instructions and builds a transaction for each. Prevents needing to spam RPC with requests for the same blockhash.

    Returns

    Parameters

    • props: Omit<TxBuildingProps, "instructions"> & {
          instructions: (TransactionInstruction | TransactionInstruction[])[];
      }

    Returns Promise<(Transaction | VersionedTransaction)[]>

  • Accepts multiple instructions and builds a transaction for each. Prevents needing to spam RPC with requests for the same blockhash.

    Returns

    Type Parameters

    • T extends Record<string, TransactionInstruction | TransactionInstruction[]>

    Parameters

    • props: Omit<TxBuildingProps, "instructions"> & {
          instructionsMap: T;
      }

    Returns Promise<MappedRecord<T, Transaction | VersionedTransaction>>

  • Parameters

    • ixs: TransactionInstruction[]
    • Optional recentBlockhash: Readonly<{
          blockhash: string;
          lastValidBlockHeight: number;
      }>

    Returns Transaction

  • Parameters

    • recentBlockhash: Readonly<{
          blockhash: string;
          lastValidBlockHeight: number;
      }>
    • ixs: TransactionInstruction[]
    • Optional wallet: IWallet

    Returns VersionedTransaction

  • Parameters

    • recentBlockhash: Readonly<{
          blockhash: string;
          lastValidBlockHeight: number;
      }>
    • ixs: TransactionInstruction[]
    • lookupTableAccounts: AddressLookupTableAccount[]
    • Optional wallet: IWallet

    Returns VersionedTransaction

  • Parameters

    • signedTx: Transaction | VersionedTransaction

    Returns string

  • Created this to prevent non-finalized blockhashes being used when building transactions. We want to always use finalized because otherwise it's easy to get the BlockHashNotFound error (RPC uses finalized to validate a transaction). Using an older blockhash when building transactions should never really be a problem right now.

    https://www.helius.dev/blog/how-to-deal-with-blockhash-errors-on-solana#why-do-blockhash-errors-occur

    Returns

    Returns Promise<Readonly<{
        blockhash: string;
        lastValidBlockHeight: number;
    }>>

  • Get a map of signed and prepared transactions from an array of legacy transactions

    Returns

    Type Parameters

    • T extends Record<string, Transaction>

    Parameters

    • txsMap: T
    • Optional wallet: IWallet
    • Optional commitment: Commitment
    • Optional recentBlockhash: Readonly<{
          blockhash: string;
          lastValidBlockHeight: number;
      }>

    Returns Promise<{
        signedTxData: SignedTxData[];
        signedTxMap: T;
    }>

  • Get a map of signed transactions from an array of transactions to sign.

    Returns

    Type Parameters

    • T extends Record<string, Transaction | VersionedTransaction>

    Parameters

    • txsToSignMap: T
    • Optional wallet: IWallet

    Returns Promise<{
        signedTxData: SignedTxData[];
        signedTxMap: T;
    }>

  • Parameters

    • signedTx: Transaction | VersionedTransaction

    Returns string

  • Parameters

    Returns {
        blockHash: string;
        lastValidBlockHeight: number;
        signedTx: Transaction | VersionedTransaction;
        txSig: string;
    }[]

  • Parameters

    • tx: Transaction | VersionedTransaction

    Returns boolean

  • Parameters

    • tx: Transaction | VersionedTransaction

    Returns boolean

  • Applies recent blockhash and signs a given transaction

    Returns

    Parameters

    • tx: Transaction
    • additionalSigners: Signer[]
    • Optional wallet: IWallet
    • Optional confirmationOpts: ConfirmOptions
    • Optional preSigned: boolean
    • Optional recentBlockhash: Readonly<{
          blockhash: string;
          lastValidBlockHeight: number;
      }>

    Returns Promise<Transaction>

  • Parameters

    • tx: Transaction
    • additionalSigners: Signer[]
    • Optional wallet: IWallet

    Returns Promise<Transaction>

  • Parameters

    • tx: VersionedTransaction
    • additionalSigners: Signer[]
    • Optional recentBlockhash: Readonly<{
          blockhash: string;
          lastValidBlockHeight: number;
      }>
    • Optional wallet: IWallet

    Returns Promise<VersionedTransaction>

  • Parameters

    • instruction: TransactionInstruction
    • computeUnits: number = 600_000
    • computeUnitsPrice: number = 0

    Returns Transaction

Generated using TypeDoc