Solana CookbookTransactions

Pay Fees with Any Token

Overview

In order to improve UX for users, apps should consider allowing users to pay for transactions using any token they have available in their wallet. This way apps do not have to sponsor transaction fees for users, but still improve UX for end users and not require them to hold SOL. This concept is often referred to as "gas abstraction" on other blockchains. Paying transaction fees with any token is enabled via two key native capabilities of Solana transactions:

  • The feePayer field in the transaction message.
  • The ability to batch instructions in a single transaction.

How to pay transaction fees with any token

To pay transaction fees with any token, you'll need to have an EOA to use as the fee payer and a transaction with an instruction that transfers tokens from the user's wallet to the fee payer's wallet. The fee payer will then forward the transaction to the Solana network and pay the transaction fees in SOL covered monetarily by the tokens it received from the user.

This flow can be simplified by using a fee relayer, like Kora, that can process a transaction for end users only if it is paid for in a configured token like USDC or USDT.

The following example shows how to pay transaction fees with any token.

import { createClient, generateKeyPairSigner, lamports } from "@solana/kit";
import { rpcAirdrop, solanaRpc } from "@solana/kit-plugin-rpc";
import { airdropPayer, payer } from "@solana/kit-plugin-signer";
import { tokenProgram } from "@solana-program/token";
// Generate keypairs for fee payer, sender, recipient, and mint
const feePayer = await generateKeyPairSigner();
const sender = await generateKeyPairSigner();
const recipient = await generateKeyPairSigner();
const mint = await generateKeyPairSigner();
console.log("Fee Payer Address:", feePayer.address);
console.log("Sender Address:", sender.address);
console.log("Recipient Address:", recipient.address);
console.log("Mint Address:", mint.address);
// Build a Kit client: fee payer (funded with 1 SOL), local RPC, and the token program plugin
const client = await createClient()
.use(payer(feePayer))
.use(
solanaRpc({
rpcUrl: "http://localhost:8899",
rpcSubscriptionsUrl: "ws://localhost:8900",
}),
)
.use(rpcAirdrop())
.use(airdropPayer(lamports(1_000_000_000n)))
.use(tokenProgram());
// Create the mint and mint 1.00 tokens to sender's ATA
const createMintIx = client.token.instructions.createMint({
newMint: mint,
decimals: 2,
mintAuthority: sender.address,
});
const mintToSenderIx = await client.token.instructions.mintToATA({
mint: mint.address,
owner: sender.address,
mintAuthority: sender,
amount: 100n,
decimals: 2,
});
const setup = await client.sendTransaction([createMintIx, mintToSenderIx]);
console.log("Transaction Signature:", setup.context.signature);
console.log("Successfully minted 1.0 tokens");
// Transfer tokens to recipient
const transferToRecipientIx = await client.token.instructions.transferToATA({
mint: mint.address,
authority: sender,
recipient: recipient.address,
amount: 50n,
decimals: 2,
});
// Pay the fee payer in tokens to cover the transaction fees.
// For a real-world application, calculate this from the SOL fee.
const reimburseFeePayerIx = await client.token.instructions.transferToATA({
mint: mint.address,
authority: sender,
recipient: feePayer.address,
amount: 50n,
decimals: 2,
});
const transfer = await client.sendTransaction([
transferToRecipientIx,
reimburseFeePayerIx,
]);
console.log("Transaction Signature:", transfer.context.signature);
console.log(
"Successfully transferred 0.5 tokens to recipient + 0.5 to fee payer",
);
Console
Click to execute the code.

It is recommended to use a fee relayer service to pay transaction fees with any token. Kora is built to support such a use case and also includes additional features like configuring which tokens are accepted as well as automatically swapping the received tokens for SOL for continued operation.

Kora, by the Solana Foundation, is a fee relayer service that allows you to relay transactions for other users. In addition to accepting fee payment for configured tokens, it also provides full fee sponsorship for transactions. More information can be found in the Kora documentation.

Is this page helpful?

Управляется

© 2026 Solana Foundation.
Все права защищены.
Связаться с нами
Pay Fees with Any Token | Solana