1

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?

  • What gas price were you using on testnet (in Gwei) and what were you using on mainnet? – Undead8 Jun 07 '21 at 03:06
  • for Ropsten it was : gas: 550000 and then when trying to deploy to main net it was : gas: 6721975 . However I have tried 550000 for main net as well and still failing. – Kirmaan Aboobaker Jun 08 '21 at 01:31
  • I think that you may be confusing gas and gas price. These are two different values. Gas is how much processing power can be used. Gas price is how much you pay for each unit of gas. Gas price is quoted in gwei and vary based on the chain usage. You contract depoyment transaction should specify the gas AND the gas price. – Undead8 Jun 08 '21 at 12:42
  • I understand the concept of both. Don't worry , Ive solved it. – Kirmaan Aboobaker Jun 09 '21 at 13:31

2 Answers2

0

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).

Cyril
  • 49
  • 5
0

Your problem may come from the fact that, although you are specifying a specific amount of gas that can be used, you are not specifying an explicit gas price for your transaction. Gas price is higher on mainnet than on testnets.

Here is a great answer explaining the two concepts.

By default, testnet probably used a low gas price, so you got a cost of 13$. However, on mainnet there is much more congestion and the gas price you need to pay is much higher. When your transaction failed, the default gas price was probably high enough that it caused the price of deployment to be greater than 100$.

Your transaction likely succeeded later when the gas price on mainnet was lower.

The best practice is to always specify an explicit gas price along with an explicit gas.

Undead8
  • 3,570
  • 9
  • 28