import { Nonce, setTransactionMessageLifetimeUsingDurableNonce } from '@solana/transaction-messages';
import { fetchNonce } from '@solana-program/system';
const nonceAccountAddress = address('EGtMh4yvXswwHhwVhyPxGrVV2TkLTgUqGodbATEPvojZ');
const nonceAuthorityAddress = address('4KD1Rdrd89NG7XbzW3xsX9Aqnx2EExJvExiNme6g9iAT');
const {
data: { blockhash },
} = await fetchNonce(rpc, nonceAccountAddress);
const nonce = blockhash as string as Nonce;
const durableNonceTransactionMessage = setTransactionMessageLifetimeUsingDurableNonce(
{ nonce, nonceAccountAddress, nonceAuthorityAddress },
tx,
);
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.