Fees and rent are a significant barrier to entry for new users of your app. Sponsor fees and rent to enable users to transact without holding SOL.
- Works with any Solana wallet. Check out Solana Wallet APIs
- No need to manage SOL. Fees and rent are sponsored and added to your bill.
When you request gas sponsorship for a transaction using a configured policy, the policy engine determines if that transaction is eligible for sponsorship. If eligible, the Gas Manager pays for the fees and rent upfront when the transaction is sent. The Gas Manager records the sponsored cost and adds it to your monthly bill.
- Fees: the cost of executing transactions
- Rent: the minimum payment to store data onchain
- Rent sponsorship is supported for
createAccountandcreateAssociatedTokenAccount. If you need support for custom programs, contact [email protected].
- Rent sponsorship is supported for
- API key from your dashboard
- Wallet APIs for Solana set up in your project if you want to enable sign up/login for creation of wallets
- A sponsorship policy to cover fees and/or rent: create a policy
Here’s an example of creating a serialized transfer transaction using JavaScript:
import * as solanaWeb3 from "@solana/web3.js";
import { connection, keypair } from "./config.ts";
const instructions = [
solanaWeb3.SystemProgram.transfer({
fromPubkey: keypair.publicKey,
toPubkey: keypair.publicKey,
lamports: 5,
}),
];
const { blockhash } = await connection.getLatestBlockhash();
const message = new solanaWeb3.TransactionMessage({
payerKey: new solanaWeb3.PublicKey(
// Placeholder: Set this to an address different than any other address included in the tx, will be replaced by alchemy's feePayer
"Amh6quo1FcmL16Qmzdugzjq3Lv1zXzTW7ktswyLDzits",
),
recentBlockhash: blockhash,
instructions,
}).compileToV0Message();
const transaction = new solanaWeb3.VersionedTransaction(message);
export const serializedTx = Buffer.from(transaction.serialize()).toString(
"base64",
);To sponsor fees and rent on Solana, 1) set the payerKey field of the transaction to the feePayer wallet that pays for the gas, and 2) the feePayer wallet must sign the transaction.
Get the feePayer address and the feePayer signature through alchemy_requestFeePayer using your gas policy ID and the serialized transaction. The Gas Manager updates the feePayer and adds the signature to the serializedTransaction if and only if the transaction satisfies the rules defined in your policy.
import {
ALCHEMY_API_KEY,
POLICY_ID,
RPC_URL,
type AlchemyFeePayerResponse,
} from "./config.ts";
import { serializedTransaction } from "./prepare.ts";
const response = await fetch(RPC_URL, {
method: "POST",
headers: {
accept: "application/json",
"content-type": "application/json",
},
body: JSON.stringify({
id: 1,
jsonrpc: "2.0",
method: "alchemy_requestFeePayer",
params: [{ policyId: POLICY_ID, serializedTransaction }],
}),
});
const data = (await response.json()) as AlchemyFeePayerResponse;
const serializedSponsoredTransaction = data.result?.serializedTransaction;Here is an example of signing and broadcasting a transaction using JavaScript:
import { VersionedTransaction } from "@solana/web3.js";
import { connection, keypair } from "./config.ts";
import { sponsoredSerializedTransaction } from "./request.ts";
const tx = VersionedTransaction.deserialize(
Buffer.from(sponsoredSerializedTransaction, "base64"),
);
tx.sign([keypair]);
const signature = await connection.sendRawTransaction(tx.serialize());