@solana/programs
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

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 takes any error — typically caused by a transaction failure — and identifies whether it 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 provide the index of the failed instruction, we need the transaction message to access its program address.
  • The programAddress of the program from which the error is expected.
  • Optionally, the expected error code of the custom program error. When provided, the function will also 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;
    }
}

Readme

Keywords

Package Sidebar

Install

npm i @solana/programs

Weekly Downloads

88,734

Version

2.1.0

License

MIT

Unpacked Size

18.4 kB

Total Files

17

Last publish

Collaborators

  • solana-devs