Skip to main content

GlamError

Custom error class for GLAM SDK operations that provides detailed error information from transactions.
class GlamError extends Error {
  message: string;
  rawError: TransactionError | null | undefined;
  programLogs?: string[];
}
message
string
Human-readable error message
rawError
TransactionError | null | undefined
Original Solana transaction error
programLogs
string[]
Program execution logs
Example:
import { GlamClient, GlamError } from '@glamsystems/glam-sdk';

try {
  await glamClient.state.initialize({
    name: stringToChars("My Fund"),
    enabled: true,
    accountType: StateAccountType.VAULT,
  });
} catch (error) {
  if (error instanceof GlamError) {
    console.error('Transaction failed:', error.message);
    console.error('Program logs:', error.programLogs);
  }
}

Error parsing utilities

parseTxError

Parses a transaction error into a human-readable message.
function parseTxError(error: any): string
error
any
required
Error object from a failed transaction
Returns: Human-readable error message Example:
import { parseTxError } from '@glamsystems/glam-sdk';

try {
  await client.sendTransaction(tx);
} catch (error) {
  const errorMessage = parseTxError(error);
  console.error('Error:', errorMessage);
}

resolveErrorCode

Resolves a program error code to a descriptive message.
function resolveErrorCode(
  code: number | string,
  staging?: boolean,
  programId?: string
): string | undefined
code
number | string
required
Error code as decimal number or hex string (e.g., “0xBB80”)
staging
boolean
Whether to use staging program IDL
programId
string
Program ID that failed (to avoid code collisions)
Returns: Error message or undefined if code not found Example:
import { resolveErrorCode } from '@glamsystems/glam-sdk';

const errorMsg = resolveErrorCode(6000); // "Unauthorized access"
const hexErrorMsg = resolveErrorCode("0x1770"); // Same as 6000

extractFailedProgramId

Extracts the program ID that failed from transaction logs.
function extractFailedProgramId(
  logs?: string[] | null
): string | undefined
logs
string[] | null
Transaction program logs
Returns: Program ID as base58 string, or undefined if not found Example:
import { extractFailedProgramId } from '@glamsystems/glam-sdk';

const programId = extractFailedProgramId(error.programLogs);
if (programId) {
  console.log('Failed program:', programId);
}

Common error scenarios

Insufficient balance

// Error: Insufficient balance for transaction
Ensure the wallet has enough SOL for:
  • Transaction fees
  • Rent for new accounts
  • Transfer amounts

Unauthorized access

// Error: Unauthorized access
Common causes:
  • Wrong wallet connected
  • Missing delegate permissions
  • Integration not enabled

Slippage exceeded

// Jupiter swap failed: Slippage tolerance exceeded
For Jupiter swaps, increase slippage tolerance:
const quote = await client.jupiterSwap.getQuote({
  inputMint,
  outputMint,
  amount,
  slippageBps: 100, // Increase from default 50
});

Account already in use

// Error: Account already in use
The account (vault, delegate, etc.) already exists. Use a different seed or address.

Build docs developers (and LLMs) love