Custom program error

0x17986040

Appears in logs as custom program error: 0x1798

Anchor

Custom error #40

“custom program error: 0x1798”

Code 6040 (0x1798) is not an Anchor framework error. Anchor programs number their own #[error_code] enum starting at 6000, so this is the 41st variant (index 40) of the error enum defined by the program you called.

Common causes

  • The program's instruction handler returned the error at index 40 of its custom error enum. What that means depends entirely on the program.

How to fix it

  • Look at the program logs: Anchor prints Error Code: <Name>. Error Number: 6040. Error Message: <text> just before the failure.
  • Open the program's IDL (on an explorer or via anchor idl fetch <programId>) and find the errors entry with code 6040.
  • In the Rust source, count variants in the #[error_code] enum: variant 40 (zero-based) is the one that fired.

How Anchor custom error numbers work

Every Anchor program declares its own errors with #[error_code]. Anchor assigns the first variant 6000, the second 6001, and so on, so they never collide with the framework’s own errors (100–5999). The hex you see in logs is simply that number in base 16: 6000 = 0x1770, 6001 = 0x1771, 6002 = 0x1772.

#[error_code]
pub enum MyError {
    #[msg("Amount must be greater than zero")]
    ZeroAmount,          // 6000 = 0x1770
    #[msg("Slippage tolerance exceeded")]
    SlippageExceeded,    // 6001 = 0x1771
    #[msg("Pool is paused")]
    PoolPaused,          // 6002 = 0x1772
}

To find out what 0x1798 means for the program you called, fetch its IDL and look at the errors array, or look for the Error Message: log line Anchor prints before the failure. The transaction decoder pulls these log lines out of a failed signature for you.

Decode another error

Try: