1

On the Client/Browser When trying to initialize a new NonceAccount following the recipe from the [Cookbook][1] & Phantom

Solana Coobook Instruction:

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

   SystemProgram.nonceInitialize({
                noncePubkey: nonceAccount.publicKey, // nonce account pubkey
                authorizedPubkey: nonceAccountAuth.publicKey, // nonce account authority (for advance and close)
            })

Problem 1:

Only works in scenarios where both accounts are being generated at runtime or all Keypairs are available from storage. (All Signers in the same Device and Runtime)

The Nonce account is generated at the client side, and it makes sense given that it is a nonce account and it is closely tied to that specific user. Storing the Keypair, encrypted in a safe place on the client is a concern. ( to be discussed elsewhere )

Issue: The given example only works when both accounts are being created in the same runtime or if the Keypairs are available in the same runtime. Meaning the Client has complete control over the NonceAccount.

Removing the error**:

In order to provide an Authority that is not in the same runtime/device, I needed to pass the PublicKey Object (removed the property)

dapp could be a merchant, a website, etc.

   const dapp = new PublicKey('Atts2amU6HedVyHrouhvqGogHw1FzgJFjbabD8iRmvhi');

   SystemProgram.nonceInitialize({
                noncePubkey: nonceAccount.publicKey, // nonce account pubkey
                authorizedPubkey: dapp, // nonce account authority (for advance and close)
            })

Problem 2:

The instruction presents no more problems at this point, but it then throws a new error when trying to send the transaction ( and sign )

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

The new error is:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'toString')
    at legacy.ts:446:47

And is caused by the previous Instruction (weird)

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,
    }),
...
  );

Solution for problem 2**:

Similar to the previous solution, removing the .publicKey property and passing the feePyer object (PublicKey Obj) resolved the problem.

enter image description here

Problem 3:

enter image description here

enter image description here

The cause of the new error is that the Phantom object doesn't contain the PublicKey object properties & methods, specifically the toBase58 method.

I am currently stuck at this point. I also tried different combinations for sending and signing using the provider ( Phantom ) but each one ended in some error.

https://docs.phantom.app/solana/sending-a-transaction

1 Answer 1

0

Solution or Workaround:

This is how I managed to get it working: https://gist.github.com/chongkan/edffe0613cad007322ea486e323e0f72

However, I am not sure this is the best approach. Feedback is appreciated.

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.