2

I want to sign the transaction using both a keypair as a backend wallet and the Phantom wallet. I am using the Solana wallet adapter package. How can I do this with the Solana wallet adapter and the backend keypair?

I have set both as a signer backend and user.

 const backend = Keypair.fromSecretKey(
    base58.decode(keypair)
  );
const tx= new transaction()
tx.add(executeSaleIX);
tx.feePayer = publicKey;
let hash = await connection.getRecentBlockhash();
 tx.recentBlockhash = hash?.blockhash;
 const ExecuteSignature = await sendTransaction(tx, connection);
 await connection.confirmTransaction(ExecuteSignature);
 console.log("\n\n\n\nExecution Done",ExecuteSignature)



1 Answer 1

2

You can partial the transaction in the backend, then send it to the frontend serialized, add the second signature in the frontend and then send it.

Here is an example on how to do this:

const transaction = await mintCompressedNft(
    CONNECTION,
    nftArgs,
    ownerWallet.publicKey,
    TreeAccount,
    CollectionMint,
    collectionMetadataAccount, 
    collectionMasterEditionAccount,
    feepayer
  );
  transaction.recentBlockhash = hash.blockhash;

  transaction.partialSign(ownerWallet);
  console.log("transaction " + transaction.instructions.length);
  
  const serializedTransaction = transaction.serialize({
    verifySignatures: false,
    requireAllSignatures: false,
  });

  const base64Transaction = serializedTransaction.toString('base64');

  res.status(200).json({
    transaction: base64Transaction,
    message: "OK",
  });

Source: https://github.com/solana-developers/one-milion-nfts/blob/main/next/pages/api/mint.ts

and then in the client you call that API and add another signature via wallet adapter:

const jsonResponse = await response.json(); //extract JSON from the http response

        const decodedTx = Buffer.from(jsonResponse.transaction, "base64");
        const transaction = Transaction.from(decodedTx);

        const signature = await sendTransaction(transaction, CONNECTION, {
          skipPreflight: true,
        });

Source: https://github.com/solana-developers/one-milion-nfts/blob/main/next/app/page.tsx#L70

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.