diff --git a/src.ts/providers/provider-etherscan-base.ts b/src.ts/providers/provider-etherscan-base.ts index 3153221fa..e85b218ef 100644 --- a/src.ts/providers/provider-etherscan-base.ts +++ b/src.ts/providers/provider-etherscan-base.ts @@ -274,6 +274,14 @@ export class BaseEtherscanProvider extends AbstractProvider { } } + if (req.method === "estimateGas") { + if (!message.match(/revert/i) && message.match(/insufficient funds/i)) { + assert(false, "insufficient funds", "INSUFFICIENT_FUNDS", { + transaction: req.transaction + }); + } + } + if (req.method === "call" || req.method === "estimateGas") { if (message.match(/execution reverted/i)) { let data = ""; @@ -287,7 +295,6 @@ export class BaseEtherscanProvider extends AbstractProvider { } } - if (message) { if (req.method === "broadcastTransaction") { const transaction = Transaction.from(req.signedTransaction); diff --git a/src.ts/providers/provider-jsonrpc.ts b/src.ts/providers/provider-jsonrpc.ts index 423631f8c..e73c57233 100644 --- a/src.ts/providers/provider-jsonrpc.ts +++ b/src.ts/providers/provider-jsonrpc.ts @@ -787,6 +787,15 @@ export abstract class JsonRpcApiProvider extends AbstractProvider { const { method } = payload; const { error } = _error; + if (method === "eth_estimateGas" && error.message) { + const msg = error.message; + if (!msg.match(/revert/i) && msg.match(/insufficient funds/i)) { + return makeError("insufficient funds", "INSUFFICIENT_FUNDS", { + transaction: ((payload).params[0]), + }); + } + } + if (method === "eth_call" || method === "eth_estimateGas") { const result = spelunkData(error);