What I would like to achieve is to make the user use the solana program for "free" and make the company pay for the transaction, what I have in mind is:
- Extrapolate the transaction in the frontend
- Send it to my backend server through an api
- Use the wallet that I have on my BE to sing and set this wallet as payer
- Send back the transaction
- Sign the transaction with the user that is interacting with the FE
- Send the transaction from the FE to the solana program.
Let's consider the hello world example https://github.com/solana-labs/example-helloworld
export async function sayHello(): Promise<void> {
console.log('Saying hello to', greetedPubkey.toBase58());
const instruction = new TransactionInstruction({
keys: [{pubkey: greetedPubkey, isSigner: false, isWritable: true}],
programId,
data: createSetInstruction()
});
console.log(instruction)
await sendAndConfirmTransaction(
connection,
new Transaction().add(instruction),
[payer],
);
}
I guess that in some way I could extrapolate the transaction before the sendAndConfirmTransaction
How can I achieve that and the sign it with my Backend wallet?
Update
In order to manage this problem, I started developing this service: cowsigner.com