0

We have a Rinkeby contract for minting NFTs. Occasionally, when it's in public-sale mode, if a person attempts to mint an NFT, the transaction fails and on the tx's etherscan it says:

Warning! Error encountered during contract execution [out of gas]

It says this even though there is definitely enough ETH in their wallet and they've set their gas max fee to 'high' on metamask. The confusing thing is that it only happens about 75% of the time. Sometimes it mints with no problems...

  • See the test contract here.
  • See the failed transaction here.

Is there anything you can see in our contract that would be causing issues with gas like this?

2 Answers 2

1

In your failed transaction, the gas used by the transaction reached the gas limit. You can check it by clicking the "Click to see more" button.

Probably this is why the transaction failed.

enter image description here

This gas limit is not related to the ETH balance of customer's wallet or to the "high" setting in MetaMask.

To avoid this, you can set the gas limit higher when you call the contract function.
For example, if you build the dapp to call the contract function by yourself and you use ethers.js for frontend, you can set the gas limit like this.

1

The issue here seems to be related to the amount of gas sent with the transaction. Usually wallets will do a good job of estimating the amount of gas required to complete a transaction and set it automatically. However, these don't work so well when smart contracts implement complex if...else controls and loops. It is difficult for the wallet to estimate what code block will be run or how many time a loop will execute.

I see in your contract ERC721A _safeMint you have some loops that may execute for a while for high number of mints. Also, the failed transaction seem to only be for mint quantities greater than 1. If the users are minting the NFT through your dapp, try increasing the gas limit for transaction and see if the transaction completes successfully.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.