assertIsTransactionWithBlockhashLifetime

function assertIsTransactionWithBlockhashLifetime(
    transaction,
): asserts transaction is Readonly<{
    messageBytes: TransactionMessageBytes;
    signatures: SignaturesMap;
}> &
    TransactionWithBlockhashLifetime;

From time to time you might acquire a transaction, that you expect to have a blockhash-based lifetime, from for example a wallet. Use this function to assert that such a transaction actually has a blockhash-based lifetime.

Parameters

ParameterType
transaction| Readonly<{ messageBytes: TransactionMessageBytes; signatures: SignaturesMap; }> | Readonly<{ messageBytes: TransactionMessageBytes; signatures: SignaturesMap; }> & TransactionWithLifetime

Returns

asserts transaction is Readonly<{ messageBytes: TransactionMessageBytes; signatures: SignaturesMap }> & TransactionWithBlockhashLifetime

Example

import { assertIsTransactionWithBlockhashLifetime } from '@solana/transactions';
 
try {
    // If this type assertion function doesn't throw, then
    // Typescript will upcast `transaction` to `TransactionWithBlockhashLifetime`.
    assertIsTransactionWithBlockhashLifetime(transaction);
    // At this point, `transaction` is a `TransactionWithBlockhashLifetime` that can be used
    // with the RPC.
    const { blockhash } = transaction.lifetimeConstraint;
    const { value: blockhashIsValid } = await rpc.isBlockhashValid(blockhash).send();
} catch (e) {
    // `transaction` turned out not to have a blockhash-based lifetime
}

On this page