Skip to main content
GET
/
api
/
:projectId
/
errors
Project Errors
curl --request GET \
  --url https://api.example.com/api/:projectId/errors
{
  "projectId": "<string>",
  "programName": "<string>",
  "errors": [
    {
      "code": 123,
      "name": "<string>",
      "msg": "<string>"
    }
  ]
}

Overview

Custom errors are defined in Anchor programs to provide meaningful error messages when instructions fail. This endpoint returns all error codes and their descriptions from the program’s IDL.

Get Program Errors

GET /api/:projectId/errors
Retrieve all custom error definitions from the program’s IDL.

Path Parameters

projectId
string
required
The unique identifier of the project

Response

projectId
string
The project identifier
programName
string
Name of the Anchor program from the IDL
errors
array
List of error definitions

Example Request

curl -X GET "https://api.orquestra.so/api/proj_abc123/errors"

Example Response

{
  "projectId": "proj_abc123",
  "programName": "token_swap",
  "errors": [
    {
      "code": 6000,
      "name": "InsufficientLiquidity",
      "msg": "The pool does not have enough liquidity for this swap"
    },
    {
      "code": 6001,
      "name": "SlippageExceeded",
      "msg": "The actual swap amount is below the minimum specified (slippage protection)"
    },
    {
      "code": 6002,
      "name": "PoolPaused",
      "msg": "This pool is currently paused and cannot process swaps"
    },
    {
      "code": 6003,
      "name": "InvalidFee",
      "msg": "Fee must be between 0 and 10000 basis points (0-100%)"
    },
    {
      "code": 6004,
      "name": "UnauthorizedAdmin",
      "msg": "Only the pool authority can perform this action"
    },
    {
      "code": 6005,
      "name": "InvalidTokenMint",
      "msg": "Token mint does not match pool configuration"
    },
    {
      "code": 6006,
      "name": "ZeroAmount",
      "msg": "Amount must be greater than zero"
    },
    {
      "code": 6007,
      "name": "MathOverflow",
      "msg": "Arithmetic overflow occurred during calculation"
    },
    {
      "code": 6008,
      "name": "MinLiquidityNotMet",
      "msg": "Initial liquidity is below the minimum required amount"
    },
    {
      "code": 6009,
      "name": "ImbalancedDeposit",
      "msg": "Token deposit ratio does not match current pool reserves"
    },
    {
      "code": 6010,
      "name": "WithdrawalTooLarge",
      "msg": "Cannot withdraw more liquidity than you have deposited"
    },
    {
      "code": 6011,
      "name": "PoolAlreadyInitialized",
      "msg": "This pool has already been initialized"
    },
    {
      "code": 6012,
      "name": "InvalidOracle",
      "msg": "Oracle price feed is invalid or stale"
    }
  ]
}

Understanding Error Codes

Anchor custom errors start at code 6000 and increment sequentially. When a transaction fails with a custom error, you’ll see the error code in the transaction logs.

Error Code Format

Anchor errors follow this pattern:
  • 0-5999: Anchor framework errors
  • 6000+: Custom program errors (defined in your IDL)

Handling Errors in Code

import { AnchorError } from '@project-serum/anchor';

try {
  await program.methods.swap(amount, minAmountOut)
    .accounts({ /* ... */ })
    .rpc();
} catch (error) {
  if (error instanceof AnchorError) {
    switch (error.error.errorCode.number) {
      case 6000:
        console.error('Insufficient liquidity in pool');
        break;
      case 6001:
        console.error('Slippage tolerance exceeded');
        break;
      case 6002:
        console.error('Pool is currently paused');
        break;
      default:
        console.error('Unknown error:', error.error.errorMessage);
    }
  }
}

Decoding Transaction Errors

When a transaction fails on-chain, the error code appears in the transaction logs:
Transaction Error Log
{
  "err": {
    "InstructionError": [
      0,
      {
        "Custom": 6001
      }
    ]
  }
}
You can map the error code (6001) to the error name (SlippageExceeded) and message using the errors endpoint.
class ErrorDecoder {
  constructor(errors) {
    this.errorMap = new Map(
      errors.map(e => [e.code, { name: e.name, msg: e.msg }])
    );
  }
  
  decode(errorCode) {
    return this.errorMap.get(errorCode) || {
      name: 'UnknownError',
      msg: `Unknown error code: ${errorCode}`
    };
  }
}

// Fetch errors and create decoder
const response = await fetch('https://api.orquestra.so/api/proj_abc123/errors');
const { errors } = await response.json();
const decoder = new ErrorDecoder(errors);

// Decode an error from transaction
const error = decoder.decode(6001);
console.log(`${error.name}: ${error.msg}`);
// Output: SlippageExceeded: The actual swap amount is below the minimum specified

Error Responses

{
  "error": "Project not found or not public"
}
The specified project ID does not exist, is private, or has no IDL uploaded.
{
  "error": "Failed to get errors"
}
The server encountered an error processing the request.

Notes

No authentication required - This endpoint is public for all public projects.
Build an error decoder utility that caches error definitions to provide better error messages in your application.
Some programs may have no custom errors defined (empty array). These programs rely solely on Anchor’s built-in errors.
Error codes are unique within a program but may overlap across different programs. Always use errors in the context of a specific program ID.

Build docs developers (and LLMs) love