Kit
Functions

assertIsTransactionMessageWithDurableNonceLifetime

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

From time to time you might acquire a transaction message, that you expect to have a nonce-based lifetime, from an untrusted network API or user input. Use this function to assert that such a transaction message actually has a nonce-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; }> & TransactionMessageWithDurableNonceLifetime<string, string, string>

Returns

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

Example

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

On this page