@@ -71,11 +71,6 @@ const estimateGasLimit = async (utx: TransactionConfig, web3: Web3) => {
71 .divn(100); // 20% cushion
71 .divn(100); // 20% cushion
74−const getMaxFeePerGas = async (web3: Web3) => {
75− const fee = await web3.eth.getGasPrice();
76− return (Number(fee) * 1.2).toFixed(0); // 20% cushion
79const signTransaction = async ({
74const signTransaction = async ({
81 walletType,
76 walletType,
@@ -92,24 +87,41 @@ const signTransaction = async ({
92}: signTransactionProps) => {
87}: signTransactionProps) => {
93 const from = wallet.address;
88 const from = wallet.address;
94 const estimate = await estimateGasLimit({ ...txn, from }, web3);
89 const estimate = await estimateGasLimit({ ...txn, from }, web3);
91+ let block = await web3.eth.getBlock('pending');
93+ // in case pending block doesn't return anything
94+ if (!block || !block.baseFeePerGas) {
95+ block = await web3.eth.getBlock('latest');
98+ const baseFeeWei = block.baseFeePerGas;
100+ // from user dropdown
101+ const maxPriorityFeePerGas = toWei(
102+ String(Math.round(gasPriceData.maxPriorityFeePerGas)),
95− const maxFeePerGas = await getMaxFeePerGas(web3);
106+ const maxFeePerGas = Math.floor(
107+ (Number(baseFeeWei) + Number(maxPriorityFeePerGas)) * 1.2 // 20% cushion
97 const txParams: EIP1559TxData = {
110 const txParams: EIP1559TxData = {
98 data: toHex(txn.data),
111 data: toHex(txn.data),
99 to: toHex(txn.to),
112 to: toHex(txn.to),
100 gasLimit: toHex(estimate),
113 gasLimit: toHex(estimate),
101 maxFeePerGas: toHex(maxFeePerGas),
114 maxFeePerGas: toHex(maxFeePerGas),
102− maxPriorityFeePerGas: toHex(
115+ maxPriorityFeePerGas: toHex(maxPriorityFeePerGas),
103− toWei(Math.round(gasPriceData.maxPriorityFeePerGas).toFixed(0), 'gwei')
105 nonce: toHex(nonce),
116 nonce: toHex(nonce),
106 chainId: toHex(chainId),
117 chainId: toHex(chainId),
107 type: toHex(EIP1559_TRANSACTION_TYPE),
118 type: toHex(EIP1559_TRANSACTION_TYPE),
110 const chain =
121 const chain =
111− (networkType === NETWORK_TYPES.GOERLI) ||
122+ networkType === NETWORK_TYPES.GOERLI || networkType === NETWORK_TYPES.LOCAL
112− (networkType === NETWORK_TYPES.LOCAL) ? Chain.Goerli : Chain.Mainnet;
123+ ? Chain.Goerli
114 const common = new Common({
126 const common = new Common({
@@ -118,7 +130,7 @@ const signTransaction = async ({
119 if (networkType === NETWORK_TYPES.LOCAL) {
131 if (networkType === NETWORK_TYPES.LOCAL) {
120 common._chainParams.chainId = 1337;
132 common._chainParams.chainId = 1337;
121− common._chainParams.name = "ganache";
133+ common._chainParams.name = 'ganache';
124 const txConfig: TxOptions = {
136 const txConfig: TxOptions = {