3

I am trying to create a sign in transaction using the following code (using react wallet adapter):

const tx = new Transaction().add(
            // create nonce account
            SystemProgram.createAccount({
            fromPubkey: 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: publicKey, // nonce account auth
            }),
            new TransactionInstruction({
                keys: [{ pubkey: publicKey, isSigner: true, isWritable: true }],
                data: Buffer.from("Data to send in transaction", "utf-8"),
                programId: new PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),
            }),

        );
        tx.feePayer = publicKey;

        const {
            context: { slot: minContextSlot },
            value: { blockhash, lastValidBlockHeight },
          } = await connection.getLatestBlockhashAndContext();
          
        try {
            const signature = await sendTransaction(tx, connection, {
                minContextSlot,
                skipPreflight: true,
                signers: [],
                preflightCommitment: 'processed',
               
              });
              console.log({ blockhash, lastValidBlockHeight, signature, minContextSlot });
        
              const confirmtx = await connection.confirmTransaction({ blockhash, lastValidBlockHeight, signature });
              console.log({ signature, confirmtx });

        } catch(err){
            console.log(err)
        }

The tx pops up, and after confirming it, I get these 2 similar errors: 1.

Phantom - RPC Error: Signature verification failed {code: -32003, message: 'Signature verification failed'}

2.

WalletSendTransactionError: Signature verification failed at PhantomWalletAdapter.sendTransaction (adapter.ts:223:23) at async WalletProviderBase.tsx:201:20 at async SignIn (Profile.jsx:101:31)

Any ideas what is the reasoning? Thanks!!!

1 Answer 1

2

You need to add the nonceAccount to your signers, since you're creating it in this transaction. So when sending the transaction, try:

              const signature = await sendTransaction(tx, connection, {
                minContextSlot,
                skipPreflight: true,
                signers: [nonceAccount],
                preflightCommitment: 'processed',
              });
0

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.