Kit
Functions

setTransactionMessageLifetimeUsingDurableNonce

setTransactionMessageLifetimeUsingDurableNonce<TTransactionMessage, TNonceAccountAddress, TNonceAuthorityAddress, TNonceValue>(__namedParameters, transactionMessage): SetTransactionMessageWithDurableNonceLifetime<TTransactionMessage, TNonceAccountAddress, TNonceAuthorityAddress, TNonceValue>

Given a nonce, the account where the value of the nonce is stored, and the address of the account authorized to consume that nonce, this method will return a new transaction having the same type as the one supplied plus the TransactionMessageWithDurableNonceLifetime type.

In particular, this method prepends an instruction to the transaction message designed to consume (or 'advance') the nonce in the same transaction whose lifetime is defined by it.

Type Parameters

Type ParameterDefault type
TTransactionMessage extends Readonly<{ instructions: readonly Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[]; version: TransactionVersion; }>-
TNonceAccountAddress extends stringstring
TNonceAuthorityAddress extends stringstring
TNonceValue extends stringstring

Parameters

ParameterType
__namedParametersDurableNonceConfig<TNonceAccountAddress, TNonceAuthorityAddress, TNonceValue>
transactionMessageTTransactionMessage

Returns

SetTransactionMessageWithDurableNonceLifetime<TTransactionMessage, TNonceAccountAddress, TNonceAuthorityAddress, TNonceValue>

Example

import { setTransactionMessageLifetimeUsingDurableNonce } from '@solana/transactions';
 
const NONCE_VALUE_OFFSET =
    4 + // version(u32)
    4 + // state(u32)
    32; // nonce authority(pubkey)
// Then comes the nonce value.
 
const nonceAccountAddress = address('EGtMh4yvXswwHhwVhyPxGrVV2TkLTgUqGodbATEPvojZ');
const nonceAuthorityAddress = address('4KD1Rdrd89NG7XbzW3xsX9Aqnx2EExJvExiNme6g9iAT');
const { value: nonceAccount } = await rpc
    .getAccountInfo(nonceAccountAddress, {
        dataSlice: { length: 32, offset: NONCE_VALUE_OFFSET },
        encoding: 'base58',
    })
    .send();
const nonce =
    // This works because we asked for the exact slice of data representing the nonce
    // value, and furthermore asked for it in `base58` encoding.
    nonceAccount!.data[0] as unknown as Nonce;
 
const durableNonceTransactionMessage = setTransactionMessageLifetimeUsingDurableNonce(
    { nonce, nonceAccountAddress, nonceAuthorityAddress },
    tx,
);

On this page