1

Is there a way to create a nonce account as a durable transaction? The use case is for fireblocks users who might timeout on conventional transactions, so we would like to use durable transactions. However, there is still the issue of creating the nonce account for the fireblocks account in the first place, which would also time out. What is the optimal way to deal with this issue, or a way to send the nonce account creation transaction as a durable transaction as well, so users can use the same flow?

2 Answers 2

1

The best choice is probably to create the nonce account in a regular transaction then use it as needed for your durable transactions. The creation of a nonce account is unlikely to time out.

1
  • Hi, the issue with that is if the people are timing out on regular transactions, how will they be able to create the nonce account?
    – Jeffrey Hu
    Commented Nov 16, 2022 at 17:51
0

There is a reference on how to do this in the [Solana Cookbook.][1]

https://solanacookbook.com/references/offline-transactions.html#create-nonce-account


import {
  clusterApiUrl,
  Connection,
  Keypair,
  Transaction,
  NONCE_ACCOUNT_LENGTH,
  SystemProgram,
  LAMPORTS_PER_SOL,
} from "@solana/web3.js";

(async () => {
  // Setup our connection and wallet
  const connection = new Connection(clusterApiUrl("devnet"), "confirmed");
  const feePayer = Keypair.generate();

  // Fund our wallet with 1 SOL
  const airdropSignature = await connection.requestAirdrop(
    feePayer.publicKey,
    LAMPORTS_PER_SOL
  );
  await connection.confirmTransaction(airdropSignature);

  const nonceAccountAuth = Keypair.generate();

  let nonceAccount = Keypair.generate();
  console.log(`nonce account: ${nonceAccount.publicKey.toBase58()}`);

  let tx = new Transaction().add(
    // create nonce account
    SystemProgram.createAccount({
      fromPubkey: feePayer.publicKey,
      newAccountPubkey: nonceAccount.publicKey,
      lamports: await connection.getMinimumBalanceForRentExemption(
        NONCE_ACCOUNT_LENGTH
      ),
      space: NONCE_ACCOUNT_LENGTH,
      programId: SystemProgram.programId,
    }),
    // init nonce account
    SystemProgram.nonceInitialize({
      noncePubkey: nonceAccount.publicKey, // nonce account pubkey
      authorizedPubkey: nonceAccountAuth.publicKey, // nonce account authority (for advance and close)
    })
  );

  console.log(
    `txhash: ${await connection.sendTransaction(tx, [feePayer, nonceAccount])}`
  );
})();

Although, I am currently struggling with the use case signature and transaction flow because the given examples always put several Keypairs in the same side of the transaction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.