Testing a smart contract for implementing very basic NFT marketplace functionality
I use HardHat with Alchemy for deployment on Polygon Mumbai TestNet
module.exports = {
defaultNetwork: "hardhat",
networks: {
hardhat: {
chainId: 1337
},
mumbai: {
url: "https://polygon-mumbai.g.alchemy.com/v2",
accounts: [privateKey]
}
}
}
const factory = await hre.ethers.getContractFactory("NFTMarket");
const market = await factory.deploy();
await market.deployed();
Everything works as expected, enjoyed it so far and would like to build on functionality
Is there any way to see upfront the gas amount required for the deployment of my contract?
Both on Ethereum Mainnet and Polygon to see the difference in costs
>Solution :
Yes, you can compile your contracts and create the transaction that would deploy your contracts without actually deploying your contracts.
You can use the hardhat gas reporter which also gives you an estimate of the gas estimation, this time it will be within hardhat.
https://github.com/cgewecke/hardhat-gas-reporter
If you have a simple contract, you can add it to https://remix.ethereum.org/ and compile it. When you hit the deploy button, there should be this pop-up
that lets you view the gas estimation, gas limit, and the current max fee, which gives you a good estimate of your transaction fee.
