Skip to main content
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:
1

Set up a fee payer wallet

Create a fee payer wallet in your backend to pay for users’ gas fees.
2

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.
3

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.
On Solana, rent refunds from Associated Token Account (ATA) closures go to the account owner rather than the fee payer. This can be exploited to drain gas sponsorship funds through repeated transactions opening and closing ATAs. See Security best practices for details and mitigation strategies before enabling sponsorship.

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:
  1. Generate a new keypair directly:
  1. Or create a Solana 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.