Skip to content

Commit 25fef4f

Browse files
committed
Fixed receipt wait not throwing on reverted transactions.
1 parent ff80b04 commit 25fef4f

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src.ts/providers/provider.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,12 +1460,27 @@ export class TransactionResponse implements TransactionLike<string>, Transaction
14601460
return;
14611461
};
14621462

1463+
const checkReceipt = (receipt: null | TransactionReceipt) => {
1464+
if (receipt == null || receipt.status !== 0) { return receipt; }
1465+
assert(false, "transaction execution reverted", "CALL_EXCEPTION", {
1466+
action: "sendTransaction",
1467+
data: null, reason: null, invocation: null, revert: null,
1468+
transaction: {
1469+
to: receipt.to,
1470+
from: receipt.from,
1471+
data: "" // @TODO: in v7, split out sendTransaction properties
1472+
}, receipt
1473+
});
1474+
};
1475+
14631476
const receipt = await this.provider.getTransactionReceipt(this.hash);
14641477

1465-
if (confirms === 0) { return receipt; }
1478+
if (confirms === 0) { return checkReceipt(receipt); }
14661479

14671480
if (receipt) {
1468-
if ((await receipt.confirmations()) >= confirms) { return receipt; }
1481+
if ((await receipt.confirmations()) >= confirms) {
1482+
return checkReceipt(receipt);
1483+
}
14691484

14701485
} else {
14711486
// Check for a replacement; throws if a replacement was found
@@ -1496,9 +1511,10 @@ export class TransactionResponse implements TransactionLike<string>, Transaction
14961511
// Done; return it!
14971512
if ((await receipt.confirmations()) >= confirms) {
14981513
cancel();
1499-
resolve(receipt);
1514+
try {
1515+
resolve(checkReceipt(receipt));
1516+
} catch (error) { reject(error); }
15001517
}
1501-
15021518
};
15031519
cancellers.push(() => { this.provider.off(this.hash, txListener); });
15041520
this.provider.on(this.hash, txListener);

src.ts/utils/errors.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,9 @@ export interface UnexpectedArgumentError extends EthersError<"UNEXPECTED_ARGUMEN
385385
// Blockchain Errors
386386

387387
/**
388-
* The action that resulted in the error.
388+
* The action that resulted in the call exception.
389389
*/
390-
export type CallExceptionAction = "call" | "estimateGas" | "getTransactionResult" | "unknown";
390+
export type CallExceptionAction = "call" | "estimateGas" | "getTransactionResult" | "sendTransaction" | "unknown";
391391

392392
/**
393393
* The related transaction that caused the error.
@@ -402,6 +402,7 @@ export type CallExceptionTransaction = {
402402
* This **Error** indicates a transaction reverted.
403403
*/
404404
export interface CallExceptionError extends EthersError<"CALL_EXCEPTION"> {
405+
405406
/**
406407
* The action being performed when the revert was encountered.
407408
*/
@@ -439,8 +440,15 @@ export interface CallExceptionError extends EthersError<"CALL_EXCEPTION"> {
439440
name: string;
440441
args: Array<any>;
441442
}
443+
444+
/**
445+
* If the error occurred in a transaction that was mined
446+
* (with a status of ``0``), this is the receipt.
447+
*/
448+
receipt?: TransactionReceipt; // @TODO: in v7, make this `null | TransactionReceipt`
442449
}
443450

451+
444452
/**
445453
* The sending account has insufficient funds to cover the
446454
* entire transaction cost.

0 commit comments

Comments
 (0)