isTransactionWithBlockhashLifetime

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

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

Parameters

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

Returns

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

Example

import { isTransactionWithBlockhashLifetime } from '@solana/transactions';
 
if (isTransactionWithBlockhashLifetime(transaction)) {
    // At this point, `transaction` has been refined to a `TransactionWithBlockhashLifetime`.
    const { blockhash } = transaction.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