How to sponsor gas on Solana
Fees and rent are a significant barrier to entry for new users of your app. With the Gas Manager, you can remove this barrier, allowing users to transact without holding SOL. You can use the Gas Manager to sponsor:
- Fees cover the cost of executing transactions.
- Rent is required to store data on-chain.
- We support rent sponsorship for SystemProgram.createAccount.
- If you need support for sponsoring rent in more programs, please contact us at [email protected].
We make it easy for you to sponsor fees/rent for any transaction: you don’t need to hold any tokens, we front the fees/rent for you and add it to your monthly bill.
[Recommended] Use our Smart Wallets SDK to create and use wallets. The SDK handles all complexity for you, making development faster and easier.
If you want to use APIs directly, follow these steps.
1. Create a Gas Manager policy
A gas manager policy defines which transactions are eligible for sponsorship. You can customize the policy to limit the amount of money or the number of transactions that can be sponsored.
You can create a policy in the Gas Manager dashboard.
Now you should have a Gas policy created with a policy id you can use to sponsor fees and rent for your users.
2. Prepare a Serialized Solana Transaction
Here’s an example of creating a serialized transfer transaction using javascript:
3. Request sponsorship for the Serialized Transaction
To sponsor fees and rent on Solana, 1) the payerKey
field of the transaction needs to be set to the feePayer wallet that will pay for the gas, 2) the feePayer wallet needs to sign the transaction.
You can get the feePayer
address and the feePayer signature through alchemy_requestFeePayer using your gas policy id and the serialized transaction. The Gas Manager will update the feePayer
and add the signature to the serializedTransaction
if and only the transaction satisfies the rules defined in your policy.
4. Sign and broadcast the Transaction
Here is an example of signing and broadcasting a transaction using javascript: