What i am trying to do this create a transcation on backend( which have pk for my wallet ) set frontend wallet as fee payer sign that transcation and send it to frontend and only if end user signs the wallet , confirm the tx and send to blockchain, This is what i have tried so far:
const walletToSendSol = new PublicKey(wallet);
const transferTransaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey: payer.publicKey,
toPubkey:walletToSendSol ,
lamports: LAMPORTS_PER_SOL / 80,
})
);
transferTransaction.recentBlockhash = (
await connection.getLatestBlockhash()
).blockhash;
transferTransaction.feePayer = walletToSendSol;
transferTransaction.sign(payer);
return new NextResponse(
JSON.stringify({
tx: base58.encode(
transferTransaction.serialize({
requireAllSignatures: false,
})
),
})
);
End user:
const fetchTx = await fetch(`/api/getTx?wallet=${publicKey}`);
const { tx } = await fetchTx.json();
const decodedTx = base58.decode(tx);
const transcation = Transaction.from(decodedTx);
transcation.feePayer = publicKey;
const signature = await signTransaction(transcation);
but once click approve on phantom wallet nothing happens