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

Commit

Permalink
Merge pull request #4276 from XWJACK/hdwallet-provider-eip1559
Browse files Browse the repository at this point in the history
support eip-1559
  • Loading branch information
eggplantzzz committed Nov 3, 2021
2 parents b47a251 + 39ba9ba commit 2b07ec5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/hdwallet-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dependencies": {
"@ethereumjs/common": "^2.4.0",
"@ethereumjs/tx": "^3.3.0",
"@trufflesuite/web3-provider-engine": "15.0.13-1",
"@trufflesuite/web3-provider-engine": "15.0.14",
"eth-sig-util": "^3.0.1",
"ethereum-cryptography": "^0.1.3",
"ethereum-protocol": "^1.0.1",
Expand Down
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);
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

0 comments on commit 2b07ec5

Please sign in to comment.