I am trying to estimate erc20 transfer fee and eth transfer fee. However, the gasestimate always return the same value for both ethTransferGasEstimate and erc20TransferGasEstimate
- ethTransferGasEstimate always = 21000
- erc20TransferGasEstimate always = 68408
[ ethTransferGasEstimate, erc20TransferGasEstimate, feeHistory, feeHistoryPendingBlock ] = await Promise.all([
await web3.eth.estimateGas(ethTransferCallData),
await usdc_contract.estimateGas.transfer(TO_ADDRESS_ETH_MAINNET, 100,{
from: FROM_ADDRESS_ETH_MAINNET
}),
await web3.eth.getFeeHistory(10, "latest",[10, 50, 90]),
await web3.eth.getFeeHistory(1, "pending",[10, 50, 90])
])
const baseFeePerGas = parseInt(feeHistoryPendingBlock.baseFeePerGas,16)
const rewardPerGas = feeHistory.reward.map(b => parseInt(b[1],16)).reduce((a, v) => a + v);
const priorityFeePerGasEstimate = Math.round(rewardPerGas/feeHistory.reward.length);
const ethTransferFee = ((baseFeePerGas+priorityFeePerGasEstimate)*ethTransferGasEstimate)/10**18
const erc20TransferFee = ((baseFeePerGas+priorityFeePerGasEstimate)*erc20TransferGasEstimate.toNumber())/10**18
console.log("--------Ethers.js----------")
console.log("gas estimate eth transfer",ethTransferGasEstimate.toString())
console.log("total fee", ethTransferFee)
console.log("gas estimate usdc_contract transfer", erc20TransferGasEstimate.toString())
console.log("total fee", erc20TransferFee)