RPC error InsufficientFundsForRent: Insufficient funds for rent

Last updated:

At a glance

Error details
PropertyValue
Applies toSolana JSON-RPC
Display stringTransaction results in an account ({account_index}) with insufficient funds for rent
RuleRent-exempt minimum, or zero
Check withgetMinimumBalanceForRentExemption
RetryableNot unchanged

Cause

Accounts must either hold at least the rent-exempt minimum for their size, or hold nothing. A transfer that leaves a wallet with a few lamports, a new account funded below its minimum, or a transfer of almost all of a balance all break this rule. It looks like an arithmetic problem and is one: the fee, the transfer and the minimum all have to fit into the same balance.

Solution

  1. Read the account index in the error and map it through the transaction's account list.
  2. Call getMinimumBalanceForRentExemption with the account's data size. Use 0 for a plain wallet.
  3. To empty a wallet, send everything minus the fee so it ends at exactly zero, or leave at least the minimum.
  4. For a new account, include the minimum in createAccount.

Example

{
  "err": {
    "InsufficientFundsForRent": {
      "account_index": 1
    }
  }
}

FAQ

Can an account hold less than the minimum?
Not as the result of a new transaction. It can end at zero, which closes it, or at the minimum or above.
Why did sending my whole balance fail?
The transfer has to leave enough for the fee and end at exactly zero or above the minimum. A balance that is a little short of either fails.