I was trying to implement a method for signing an eip-1559 transaction using @ethereumjs/tx
package. While following the steps mentioned in their documentation , I am encountering an error when trying to initialize the class Common
of the @ethereumjs/common
package.
Method :
const { FeeMarketEIP1559Transaction } = require('@ethereumjs/tx');
const Common = require('@ethereumjs/common');
const { Chain, Hardfork } = require('@ethereumjs/common');
async function signTx(to, from, value, gasLimit, nonce) {
const privateKey = 'private_key'
const rawTx = { to, from, value, gasLimit, data: '0x00', nonce }
const pkey = Buffer.from(privateKey, 'hex');
const common = new Common({ chain: Chain.Ropsten, hardfork: Hardfork.London });
const tx = FeeMarketEIP1559Transaction.fromTxData(rawTx, { common })
tx.sign(pkey);
const signedTx = `0x${tx.serialize().toString('hex')}`;
return signedTx;
}
Error :
UnhandledPromiseRejectionWarning: TypeError: Common is not a constructor
Package versions :
@ethereumjs/common
:2.4.0
@ethereumjs/tx
:3.3.0
Any help on this would be highly appreciated..