How to collect Token-2022 transfer fees

A Token-2022 transfer fee is not paid to you when a trade happens. It is withheld in the receiving account and waits there until your wallet collects it. Here is where it sits, how much builds up and how it gets to you.

Where the fee goes on each transfer

When someone sends a Token-2022 token that has the transfer fee extension, the token program takes the fee out of the amount received. The sender's balance drops by the full amount, the recipient's spendable balance rises by the amount minus the fee, and the fee itself is recorded as a withheld amount on the recipient's token account.

That withheld amount cannot be spent or moved by the holder. It belongs to whoever holds the mint's withdraw withheld authority. On a token minted with Anvilmint, that is the wallet that created it. Anvilmint's code passes your connected address as that authority and never an address of its own, so we could not collect your fees even if we wanted to.

How much is withheld

The fee is the rate times the amount transferred, rounded up to the token's smallest unit. Anvilmint lets you set a rate from 0.1% to 10% and an optional cap: the most that can be withheld from any single transfer, in whole tokens. Some examples:

Transfer fee withheld for example transfers
TransferRateCapWithheldRecipient gets
10,000 tokens 2% None 200 tokens 9,800 tokens
1,000,000 tokens 2% None 20,000 tokens 980,000 tokens
1,000,000 tokens 2% 5,000 tokens 5,000 tokens 995,000 tokens
1,000,000 tokens 0.5% None 5,000 tokens 995,000 tokens

A trade on a DEX is a transfer too, in both directions, so a buy and a later sell are each charged. That is the point of a transfer fee, and it is also why rates above a few percent tend to stop trading altogether.

Two ways the fees reach your wallet

The token program offers two routes, and the right one depends on how many accounts hold withheld fees.

Withdraw straight from holder accounts

Your wallet, as withdraw authority, sends one transaction listing token accounts that hold withheld fees. The fees move from those accounts into a token account of yours. This needs your signature and works well when a handful of accounts, such as a liquidity pool's vault, hold most of the fees.

Harvest to the mint, then withdraw from the mint

Anyone can harvest: move withheld fees from many holder accounts onto the mint account itself. No authority is needed, which is how holders clear an account before closing it. Your wallet then withdraws everything sitting on the mint in one step. With hundreds of holders this is the practical route, because a single transaction can only list so many accounts.

Doing it in practice

  1. Find the accounts holding fees. An explorer such as Solscan lists your token's holders. The pool's token vault is usually the largest source, because every trade passes through it.
  2. Use a tool that signs with your wallet. Anvilmint's Collect Tax Fees tool does this for 0.1 SOL a run, with the network fee covered, and other Solana token tools offer the same. Developers can use the official spl-token command line tool, which has a withdraw-withheld-tokens command. Check its --help for the exact arguments in your version.
  3. Sign from the withdraw authority wallet. Any other wallet is rejected by the token program, so connect the one that created the token.
  4. Check the result. The collected tokens appear as a normal, spendable balance in your token account.

Never give a seed phrase or private key to anything that offers to collect fees for you. A legitimate tool asks your wallet to sign, and your wallet shows you the transaction first.

What holders and buyers see

Everything about the fee is public. Explorers show the rate, the cap, the withdraw authority and the config authority on the mint. Because your wallet holds the config authority, it can change the rate, and buyers can see that it can. Token-2022 only applies a new rate two epochs after it is set, roughly four to five days, so a change is never instant. If you want holders to trust the rate, say publicly what it is for and leave it alone.

Support for Token-2022 still varies between wallets, DEXs and bridges. Check that the places you want your token traded handle the transfer fee extension before you mint. SPL vs Token-2022 covers the trade-off.

Common questions

Where do Token-2022 transfer fees go?
Nowhere at first. The fee is withheld inside the token account that received the transfer, as a separate withheld balance the holder cannot spend. It stays there until the withdraw authority collects it.
Who can collect the transfer fees?
Only the withdraw withheld authority set on the mint. On tokens minted with Anvilmint that is the wallet that created the token. Anvilmint never holds that authority and cannot collect the fees.
Do transfer fees arrive in my wallet automatically?
No. Withheld fees accumulate across every holder's token account until your wallet sends a transaction to withdraw them. Nothing is swept for you.
Can holders close their token account if it holds withheld fees?
Not until the withheld amount is moved to the mint. Moving it, called harvesting, can be done by anyone, so a holder can harvest and then close. The fees still belong to the withdraw authority, they just wait on the mint instead.
Can I change the transfer fee rate later?
Yes, with the transfer fee config authority, which on Anvilmint tokens is also your wallet. A new rate only applies two epochs after it is set, roughly four to five days, so holders get notice and can see the change on chain.

Mint a token with a transfer fee

Set the rate and an optional cap. Your wallet is the only one that can collect what it withholds. 0.5 SOL, network fees included.