1 min read

Cannot close account: it has withheld transfer fees

What you see
Error processing Instruction N: custom program error: 0x22

A Token-2022 token account cannot be closed while it still holds withheld transfer fees. Harvest the withheld fees to the mint first, then close the account.

The exact error

In the Token-2022 program, code 34 (0x22) is AccountHasWithheldTransferFees: "An account can only be closed if its withheld fee balance is zero, harvest fees to the mint and try again".

What the error means

You tried to close a token account for a Token-2022 token that charges a transfer fee. The account still holds fees withheld from earlier transfers, so Solana refuses to close it and lose that balance.

Fix

  1. Run a harvest on the account so its withheld amount moves to the mint. Anyone can do this, and the spl-token CLI has a harvest-withheld-tokens subcommand.
  2. Close the account again. The rent returns to your wallet.

If it still fails

  • Make sure the token balance is zero as well. Only empty accounts can be closed.
  • Check that you own the account.

Related: how to collect Token-2022 transfer fees and how to reclaim SOL rent.

Questions

Does harvesting give me the fees?

No. It moves them to the mint. The withdraw withheld authority then withdraws them.

Who can harvest?

Anyone.

More error fixes

All 52 →