Best solution to catch error/success in Typescript #2772
-
Hi everyone,
But as you can see, there some problemes with this syntax: Do you have any advices to give me ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
There TransactionResponse documentation covers this under the try {
// Send the transaction
const tx = await contract.function(params);
// [ here the transaction is in the mempool but not mined ]
// Wait for the transaction to become mined
const receipt = await tx.wait();
// [ here the transaction completed with success ]
} catch(error: any) {
if (error.code === Logger.errors.CALL_EXCEPTION) {
// The receipt
console.log(error.receipt);
} else if (error.code === Logger.errors.TRANSACTION_REPLACED) {
// The receipt of the replacement transaction
console.log(error.receipt);
// The reason ("repriced", "cancelled" or "replaced")
console.log(error.reason);
// The transaction that replaced this one
console.log(error.replacement);
} else {
// This shouldn't really happen; maybe server error, like the internet connection failed?
}
} Does that make sense? |
Beta Was this translation helpful? Give feedback.
There TransactionResponse documentation covers this under the
.wait
section, but in general you would want this pattern: