RPC error InstructionError Custom: custom program error: 0x…

Last updated:

At a glance

Error details
PropertyValue
Applies toSolana JSON-RPC
Display stringcustom program error: {num:#x}
Defined byThe failing program
Anchor user errorsStart at 6000 (0x1770)
RetryableDepends on the program: a slippage check can pass on fresh state

Cause

Solana passes the code through without interpreting it: custom program error: 0x1771 means only that a program returned 6001. The same number means different things in different programs, so no universal table exists, and a search for the hex value alone often finds someone else's program. The log line above the failure identifies which program returned it.

Solution

  1. Find the program: in the logs, the last Program <id> invoke before failed is the one that returned the code.
  2. Convert hex to decimal. 0x1771 is 6001.
  3. On Anchor programs, user-defined errors start at 6000, so subtract 6000 to get the index in the errors list of the IDL.
  4. Otherwise check the program's source or published error list. Ask for the IDL with the program's own tooling.
  5. When the error is a slippage check, rebuild with fresh state or a wider tolerance. Retrying the same bytes returns the same code.

Example

{
  "err": {
    "InstructionError": [
      3,
      {
        "Custom": 6001
      }
    ]
  }
}

FAQ

What does custom program error 0x1 mean?
It depends on the program. In the SPL Token program, code 1 is insufficient funds, but the same number in another program means something else. Always identify the program first.
Why does error.data show Custom: 6001 when the message says 0x1771?
They are the same number: the message prints hex, and the structured error prints decimal.