assertIsTransactionMessageWithBlockhashLifetime

function assertIsTransactionMessageWithBlockhashLifetime(
    transactionMessage,
): asserts transactionMessage is TransactionMessage &
    TransactionMessageWithBlockhashLifetime;

From time to time you might acquire a transaction message, that you expect to have a blockhash-based lifetime, from an untrusted network API or user input. Use this function to assert that such a transaction message actually has a blockhash-based lifetime.

Parameters

ParameterType
transactionMessage| TransactionMessage | TransactionMessage & TransactionMessageWithBlockhashLifetime

Returns

asserts transactionMessage is TransactionMessage & TransactionMessageWithBlockhashLifetime

Example

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

On this page