Skip to content

Best solution to catch error/success in Typescript #2772

Answered by ricmoo
BowgartField asked this question in Q&A
Discussion options

You must be logged in to vote

There TransactionResponse documentation covers this under the .wait section, but in general you would want this pattern:

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.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@BowgartField
Comment options

@ricmoo
Comment options

@BowgartField
Comment options

@ricmoo
Comment options

@BowgartField
Comment options

Answer selected by BowgartField
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
documentation Documentation related issue.
2 participants
Converted from issue

This discussion was converted from issue #2770 on March 08, 2022 19:09.