I am facing the issue while swapping the tokens using Jupiter API, I want to swap from other and feepayer will be another account. while swapping the feepayer account error show:
Error Swap: Cannot sign with non signer key HAD84928941Nt*****
const userWalletAddress = userWallet.payer.publicKey.toString();
const payerWalletAddress = payerWallet.payer.publicKey.toString();
const swapTransaction = await (
await fetch("https://quote-api.jup.ag/v6/swap", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
quoteResponse,
userPublicKey: userWalletAddress,
wrapUnwrapSOL: wrapUnwrapSOL,
dynamicComputeUnitLimit: true,
prioritizationFeeLamports: "auto",
}),
})
).json();
const swapTransactionBuf = Buffer.from(
swapTransaction.swapTransaction,
"base64"
);
var transaction = VersionedTransaction.deserialize(swapTransactionBuf);
const getblockhash = await connection.getLatestBlockhash("finalized");
transaction.recentBlockhash = getblockhash.blockhash;
transaction.feePayer = payerWallet.payer.publicKey;
transaction.sign([userWallet.payer , payerWallet.payer]);
const rawTransaction = transaction.serialize();
const txid = await connection.sendRawTransaction(rawTransaction, {
skipPreflight: true,
maxRetries: 20,
preflightCommitment: "processed",
});
await connection.confirmTransaction(txid, "finalized");
console.log(`https://solscan.io/tx/${txid}`);
userWalletAddress