[Ethereum] Super Confused Regarding Gas Fees

contract-deployment

I hope your all doing well and staying safe.

I just finished my first Dapp and Im trying to deploy it to the main net but I am suffering. So my dapp interacts with a super simple contract , the total contract is 25 lines.

Upon building I obviously had to test the contract several times and each time I deployed it to the test network (wether rinkeby or ropsten) , the gas cost was no more than $13 at absolute max. So I based the gas fees cost around $100 for the main net. I thought even if its double or triple , I will still have enough.

However that does not seem to be the case. I keep receiving an insufficient funds error. Ive tried through HardHat and Truffle. I am unable to view the required amount of gas either so Im really in limbo. Can someone possibly guide me in the right direction regarding the cost of the deployment of this contract? (I have attached it below)

contract MyNFT is ERC721 {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;

constructor() public ERC721("DistroToken", "DTKN") {}

function mintNFT(address recipient, string memory tokenURI)
    public
    returns (uint256)
{
    _tokenIds.increment();

    uint256 newItemId = _tokenIds.current();
    _mint(recipient, newItemId);
    _setTokenURI(newItemId, tokenURI);

    return newItemId;
}

}

Thank you very much!

Edit : So after attempting to deploy it through HardHat today on default settings , it went through! I wonder if the drop in crypto prices is responsible?

Best Answer

You can try to estimate the gas needed by your transaction by using the method estimateGas() from web3.js (https://web3js.readthedocs.io/en/v1.2.5/web3-eth.html?highlight=estimategas#estimategas).

Then multiply it by the current gas price (check https://etherscan.io/gastracker).

Related Topic