isTransactionMessageWithBlockhashLifetime

function isTransactionMessageWithBlockhashLifetime(
    transactionMessage,
): transactionMessage is Readonly<{
    instructions: readonly Instruction<
        string,
        readonly (
            | AccountLookupMeta<string, string>
            | AccountMeta<string>
        )[]
    >[];
    version: TransactionVersion;
}> &
    TransactionMessageWithBlockhashLifetime;

A type guard that returns true if the transaction message conforms to the TransactionMessageWithBlockhashLifetime type, and refines its type for use in your program.

Parameters

ParameterType
transactionMessage| Readonly<{ instructions: readonly Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[]; version: TransactionVersion; }> | Readonly<{ instructions: readonly Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[]; version: TransactionVersion; }> & TransactionMessageWithBlockhashLifetime

Returns

transactionMessage is Readonly<{ instructions: readonly Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[]; version: TransactionVersion }> & TransactionMessageWithBlockhashLifetime

Example

import { isTransactionMessageWithBlockhashLifetime } from '@solana/transaction-messages';
 
if (isTransactionMessageWithBlockhashLifetime(message)) {
    // At this point, `message` has been refined to a `TransactionMessageWithBlockhashLifetime`.
    const { blockhash } = message.lifetimeConstraint;
    const { value: blockhashIsValid } = await rpc.isBlockhashValid(blockhash).send();
    setBlockhashIsValid(blockhashIsValid);
} else {
    setError(
        `${getSignatureFromTransaction(transaction)} does not have a blockhash-based lifetime`,
    );
}

On this page