Created
March 28, 2022 10:12
-
-
Save hashtafak/3bdf0aa02c539c910ad0f061c9450e0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ethers = require('ethers') | |
const provider = new ethers.providers.JsonRpcProvider("https://polygon-rpc.com"); | |
// const provider = new ethers.providers.JsonRpcProvider("https://psdolygon-rpc.com"); | |
(async () => { | |
// wei => gwei => hex (bignumber) | |
// gwei => ethers.utils.hexlify => hex (bignumber) | |
// wei => ethers.utils.parseUnits gwei => hex (bignumber) | |
let estimatedGasFeesWei = 30.013769176 | |
console.log(`estimatedGasFeesWei: ${estimatedGasFeesWei}`); | |
console.log(`estimatedGasFees: ${ethers.utils.parseUnits(estimatedGasFeesWei.toString(), "gwei")}`); | |
const gas_price = ethers.utils.parseUnits(estimatedGasFeesWei.toString(), "gwei"); | |
console.log(`gas_price: ${gas_price}`); | |
const gas_price0 = ethers.utils.hexlify(parseInt(ethers.utils.parseUnits(estimatedGasFeesWei.toString(), "gwei"), 10)); | |
console.log(`gas_price0: ${gas_price0}`); | |
const overrides = { | |
gasLimit: 88654, | |
gasPrice: ethers.utils.parseUnits(estimatedGasFeesWei.toString(), "gwei"), | |
nonce: 1 | |
}; | |
console.log(overrides); | |
const currentGasPrice = await provider | |
.getGasPrice() | |
.catch((error) => { | |
console.log(error.message); | |
return ethers.utils.parseUnits("35", "gwei"); | |
}); | |
console.log(`currentGasPriceWei: ${ethers.utils.formatUnits(currentGasPrice.toString(), 9)}`); | |
console.log(`currentGasPrice: ${currentGasPrice}`); | |
const gas_price1 = ethers.utils.hexlify(parseInt(currentGasPrice, 10)); | |
console.log(`gas_price1: ${gas_price1}`); | |
const overrides1 = { | |
gasLimit: ethers.utils.hexlify(71362, 10), | |
gasPrice: gas_price1, | |
nonce: 1 | |
}; | |
console.log(overrides1); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment