diff --git a/package.json b/package.json index b0c49cc..f195d70 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tx-manager", - "version": "0.2.5", + "version": "0.2.6", "description": "", "main": "index.js", "scripts": { diff --git a/src/Transaction.js b/src/Transaction.js index 3779ed9..75634a3 100644 --- a/src/Transaction.js +++ b/src/Transaction.js @@ -175,9 +175,6 @@ class Transaction { this.currentTxHash = null continue } - if (Number(receipt.status) === 0) { - throw new Error('Transaction failed') - } const currentBlock = await this._provider.getBlockNumber() const confirmations = Math.max(0, currentBlock - receipt.blockNumber) @@ -185,6 +182,9 @@ class Transaction { this._emitter.emit('confirmations', confirmations) if (confirmations >= this.config.CONFIRMATIONS) { // Tx is mined and has enough confirmations + if (this.config.THROW_ON_REVERT && Number(receipt.status) === 0) { + throw new Error('EVM execution failed, so the transaction was reverted.') + } return receipt } @@ -237,10 +237,6 @@ class Transaction { } } - if (Number(receipt.status) === 0) { - throw new Error('Transaction failed') - } - this._emitter.emit('mined', receipt) this.currentTxHash = receipt.transactionHash } diff --git a/src/TxManager.js b/src/TxManager.js index 18847cc..7de0582 100644 --- a/src/TxManager.js +++ b/src/TxManager.js @@ -13,6 +13,7 @@ const defaultConfig = { POLL_INTERVAL: 5000, CONFIRMATIONS: 8, ESTIMATE_GAS: true, + THROW_ON_REVERT: true, } class TxManager {