Sponsoring transactions on Solana
With embedded wallets, your app can sponsor gas fees for transactions on Solana, allowing users to transact without a SOL balance.
This is done by configuring the feePayer
property of the sponsored transaction to be a fee payer wallet that your app manages to pay users’ gas fees.
Overview
Sponsoring transactions on Solana involves the following steps:
Set up a fee payer wallet
Create a fee payer wallet in your backend to pay for users’ gas fees.
Prepare and sign the transaction
Prepare a transaction with a custom fee payer, sign it with the user’s wallet, and send it to your backend.
Verify and complete the transaction
Verify the transaction, sign it with the fee payer wallet, and broadcast it to the network.
To prepare transactions with a fee payer, we recommend using the @solana/web3.js library.
Setting up a fee payer wallet
To start, create a fee payer wallet in your backend to sponsor transactions sent by users. You can either:
- Generate a new keypair directly:
- Or create a Solana server wallet to act as your fee payer for better security and key management.
Ensure you fund this wallet with SOL to pay for transaction fees.
Implementing Sponsored Transactions
With the React SDK, follow these steps to prepare and send a sponsored transaction:
Backend Implementation
Here’s how to implement the server-side portion that receives the partially signed transaction, adds the fee payer signature, and broadcasts it:
Security Considerations
When implementing transaction sponsorship, be mindful of these security considerations:
Verify Transaction Contents
Always verify the transaction contents in your backend before signing with the fee payer. Ensure there are no unauthorized fund transfers.
Rate Limiting
Implement rate limiting to prevent abuse of your sponsorship service. Consider limits per user, per session, or per wallet.
Amount Validation
Validate the transaction amount if applicable. Consider setting maximum sponsorship amounts to prevent excessive spending.
Program ID Whitelisting
Only sponsor transactions for specific whitelisted program IDs that your app interacts with to prevent abuse.
Be extremely careful with your fee payer wallet’s private key. Never expose it in client-side code or store it in unsecured environments. Consider using environment variables, secret management services, or HSMs to securely store private keys in production.
Was this page helpful?