Reputation: 31
Hi got next error in communication between dex exchange and phantom wallet
#1 Unknown program instruction
Program log: free_supply: 14100789713994 Program log: Custom program error: 0x179d Program Zo1ggzTUKMY5bYnDvT5mtVeZxzf2FaLTbKkmvGUhUQk consumed 41719 of 1400000 compute units Program returned error: custom program error: 0x179d
what might cause the issue?
Upvotes: 3
Views: 3568
Reputation: 123058
Frank's answer is excellent, but I wanted to give some additional code to show how to convert the errors.
The example below is for SPL Token Library, if you're using a different on-chain program, substitute the errors from that programs errors.rs
:
// Some SPL transactions will give
// errors like 'custom program error: 0x1'
// These are what those errors mean (eg, 1 means "Insufficient funds")
// TODO: fix upstream. The TS SDK should give real errors.
// https://github.com/solana-labs/solana-program-library/blob/master/token/program/src/error.rs
enum customProgramErrors {
"Lamport balance below rent-exempt threshold",
"Insufficient funds",
"Invalid Mint",
"Account not associated with this Mint",
"Owner does not match",
"Fixed supply",
"Already in use",
"Invalid number of provided signers",
"Invalid number of required signers",
"State is unititialized",
"Instruction does not support native tokens",
"Non-native account can only be closed if its balance is zero",
"Invalid instruction",
"State is invalid for requested operation",
"Operation overflowed",
"Account does not support specified authority type",
"This token mint cannot freeze accounts",
"Account is frozen",
"The provided decimals value different from the Mint decimals",
"Instruction does not support non-native tokens",
}
And a function to give you good error messages:
export const getABetterErrorMessage = (errorMessage: string) => {
const customErrorExpression =
/.*custom program error: 0x(?<errorNumber>[0-9abcdef])/;
let match = customErrorExpression.exec(errorMessage);
const errorNumberFound = match?.groups?.errorNumber;
if (!errorNumberFound) {
return null;
}
// errorNumberFound is a base16 string
const errorNumber = parseInt(errorNumberFound, 16);
return customProgramErrors[errorNumber] || null;
};
Upvotes: 1
Reputation: 8088
When you see custom program error...
it indicates that a program instruction in your transaction failed. The 0x179d
is the program's code which may be a unique error code, often times it is an index (variant) of a Rust enum in the program error.rs
.
For example:
pub enum SampleError {
InvalidInstruction,
DeserializationFailure,
AlreadyInitializedState,
KeyNotFoundInAccount,
KeyAlreadyExists,
InsufficientFundsForTransaction,
UnknownError,
}
So here, you could possibly see an error code of 0x0
through 0x6
. A program may also assign the error code in some other way.
In order for you to know what the error associated to the code is you can either look up the error in the programs source code. If the program you are calling is not open source... you can try to contact the owner of the program to get more information about the code.
Upvotes: 4