Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

support eip-1559 #4276

Merged
merged 3 commits into from
Nov 3, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/hdwallet-provider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { wordlist } from "ethereum-cryptography/bip39/wordlists/english";
import * as EthUtil from "ethereumjs-util";
import ethJSWallet from "ethereumjs-wallet";
import { hdkey as EthereumHDKey } from "ethereumjs-wallet";
import { Transaction } from "@ethereumjs/tx";
import { Transaction, FeeMarketEIP1559Transaction } from "@ethereumjs/tx";
import Common from "@ethereumjs/common";

// @ts-ignore
Expand Down Expand Up @@ -125,7 +125,7 @@ class HDWalletProvider {
this.hardfork =
chainSettings && chainSettings.hardfork
? chainSettings.hardfork
: "istanbul";
: "london";

const self = this;
this.engine.addProvider(
Expand Down Expand Up @@ -157,7 +157,7 @@ class HDWalletProvider {
const KNOWN_CHAIN_IDS = new Set([1, 3, 4, 5, 42]);
let txOptions;
if (typeof chain !== "undefined" && KNOWN_CHAIN_IDS.has(chain)) {
txOptions = { common: new Common({ chain }) };
txOptions = { common: new Common({ chain, hardfork: self.hardfork }) };
} else if (typeof chain !== "undefined") {
txOptions = {
common: Common.forCustomChain(
Expand All @@ -170,7 +170,13 @@ class HDWalletProvider {
)
};
}
const tx = Transaction.fromTxData(txParams, txOptions);

// Taken from https://github.com/ethers-io/ethers.js/blob/2a7ce0e72a1e0c9469e10392b0329e75e341cf18/packages/abstract-signer/src.ts/index.ts#L215
const hasEip1559 = (txParams.maxFeePerGas !== undefined || txParams.maxPriorityFeePerGas !== undefined);
eggplantzzz marked this conversation as resolved.
Show resolved Hide resolved
const tx = hasEip1559 ?
FeeMarketEIP1559Transaction.fromTxData(txParams, txOptions) :
Transaction.fromTxData(txParams, txOptions);

const signedTx = tx.sign(pkey as Buffer);
const rawTx = `0x${signedTx.serialize().toString("hex")}`;
cb(null, rawTx);
Expand Down