Kit
Functions

assertIsTransactionMessageWithBlockhashLifetime

assertIsTransactionMessageWithBlockhashLifetime(transactionMessage): asserts transactionMessage is Readonly<{ instructions: readonly Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[]; version: TransactionVersion }> & 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
transactionMessageReadonly<{ 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

asserts transactionMessage is Readonly<{ instructions: readonly Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[]; version: TransactionVersion }> & 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