Skip to content

Commit 7274cd0

Browse files
committed
Fixed JsonRpcProvider for pre-EIP-2930 chains (ethers-io#1766).
1 parent be3854e commit 7274cd0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

packages/providers/src.ts/json-rpc-provider.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,24 @@ export class JsonRpcProvider extends BaseProvider {
526526
}
527527

528528
async perform(method: string, params: any): Promise<any> {
529+
// Legacy networks do not like the type field being passed along (which
530+
// is fair), so we delete type if it is 0 and a non-EIP-1559 network
531+
if (method === "call" || method === "estimateGas") {
532+
const tx = params.transaction;
533+
if (tx && tx.type != null && BigNumber.from(tx.type).isZero()) {
534+
// If there are no EIP-1559 properties, it might be non-EIP-a559
535+
if (tx.maxFeePerGas == null && tx.maxPriorityFeePerGas == null) {
536+
const feeData = await this.getFeeData();
537+
if (feeData.maxFeePerGas == null && feeData.maxPriorityFeePerGas == null) {
538+
// Network doesn't know about EIP-1559 (and hence type)
539+
params = shallowCopy(params);
540+
params.transaction = shallowCopy(tx);
541+
delete params.transaction.type;
542+
}
543+
}
544+
}
545+
}
546+
529547
const args = this.prepareRequest(method, params);
530548

531549
if (args == null) {

0 commit comments

Comments
 (0)