JSPM

@solana/programs

4.0.0-canary-20250930182729
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 242082
  • Score
    100M100P100Q180551F
  • License MIT

Helpers for defining programs and resolving program errors

Package Exports

  • @solana/programs

Readme

npm npm-downloads
code-style-prettier

@solana/programs

This package contains helpers for identifying custom program errors. It can be used standalone, but it is also exported as part of Kit @solana/kit.

Functions

isProgramError()

This function identifies whether an error -- typically caused by a transaction failure -- is a custom program error from the provided program address. It takes the following parameters:

  • The error to identify.
  • The transactionMessage object that failed to execute. Since the RPC response only provides the index of the failed instruction, the transaction message is required to determine its program address.
  • The programAddress of the program from which the error is expected to have originated.
  • Optionally, the expected error code of the custom program error. When provided, the function will check that the custom program error code matches the given value.
try {
    // Send and confirm your transaction.
} catch (error) {
    if (isProgramError(error, transactionMessage, myProgramAddress, 42)) {
        // Handle custom program error 42 from this program.
    } else if (isProgramError(error, transactionMessage, myProgramAddress)) {
        // Handle all other custom program errors from this program.
    } else {
        throw error;
    }
}