# Dont understand \> \[out of gas\] \< and how to fix this?

**URL:** <https://forum.openzeppelin.com/t/dont-understand-out-of-gas-and-how-to-fix-this/27020>\
**Category:** Smart Contracts\
**Created:** [March 30, 2022, 2:15pm UTC](https://forum.openzeppelin.com/t/dont-understand-out-of-gas-and-how-to-fix-this/27020 "2022-03-30T14:15:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alagosul](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/alagosul/32/11854_2.png) [@alagosul](https://forum.openzeppelin.com/u/alagosul)\
**Post date:** [March 30, 2022, 2:15pm UTC](https://forum.openzeppelin.com/t/dont-understand-out-of-gas-and-how-to-fix-this/27020/1 "2022-03-30T14:15:28Z")

</div>

Hello guys,

I hope, im in the correct sub-forum.  
Im not a Pro in this.  
Started since few Days with Smart Contract Deploy NFT's.  
Im not founded a solution in Forums/Google...

I use openzeppelin...

my hardhat.config looks like this:

```auto
    PolygonMumbai : {
      url: "https://rpc-mumbai.maticvigil.com", 
      accounts: [PRIVATE_KEY],
    }

```

With this some Transactions not worked.

Failed Transactions: [https://mumbai.polygonscan.com/tx/0xe8aa6a104c751fb432c56ae3d0f64cd9a60a83d17757d97142887c48fbb2ee09](https://mumbai.polygonscan.com/tx/0xe8aa6a104c751fb432c56ae3d0f64cd9a60a83d17757d97142887c48fbb2ee09)

Worked Transactions:

> **[Polygon Transaction Hash (Txhash) Details | PolygonScan](https://mumbai.polygonscan.com/tx/0x6b2a548afcebb1222c73ef47233554e049404a0b3c5a0fee9d8d88f46490dea6)**
>
> Polygon (MATIC) detailed transaction info for txhash 0x6b2a548afcebb1222c73ef47233554e049404a0b3c5a0fee9d8d88f46490dea6. The transaction status, block confirmation, gas fee, MATIC, and token transfer are shown.

Failed Transaction: Gas Used by Transaction: 144,053 (100%)  
Worked Transaction: Gas Used by Transaction: 150,053 (100%)

Why was the Transaction success with more Gas than the Failed one with less Gasfees?

I tested with gaslimit in the config:

```auto
  matic: {
      url: "https://matic-mumbai.chainstacklabs.com",
      accounts: [PRIVATE_KEY],
      gasPrice: 8000000000, // default is 'auto' which breaks chains without the london hardfork
    }

```

But it ends in the same without, some Transactions Fails...

Does anyone know why thats happens, and how i can solve this Problem?

its a bit ugly, when i mint in mainnet, and then some nfts missing and tokenid is then wrong because of the missed one.

I minting with this code, can i add something that automatic check if the mint transaction success, if no, try again, or is this not needed if i can solve the gas error limit?

```auto
// Contract based on https://docs.openzeppelin.com/contracts/4.x/erc721
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract ExampleNFT is ERC721URIStorage, Ownable {
   using Counters for Counters.Counter;
   Counters.Counter private _tokenIds;

   constructor() ERC721("NFT", "ENFT") {}

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

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

       return newItemId;
   }
}

```

```auto
async function mintNFT(contractAddress, metaDataURL) {
   const ExampleNFT = await ethers.getContractFactory("ExampleNFT")
   const [owner] = await ethers.getSigners()
   await ExampleNFT.attach(contractAddress).mintNFT(owner.address, metaDataURL)
   console.log("NFT minted to: ", owner.address)
}

```

---

<div class="post-metadata">

**Author:** ![alagosul](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/alagosul/32/11854_2.png) [@alagosul](https://forum.openzeppelin.com/u/alagosul)\
**Post date:** [April 1, 2022, 11:57am UTC](https://forum.openzeppelin.com/t/dont-understand-out-of-gas-and-how-to-fix-this/27020/2 "2022-04-01T11:57:35Z")

</div>

I know now, the failed Transactions has something to do with the gas"limit",

I add now another Question to my first question:

I have found on google more Configs for the hardhat.

gasPrice: 8000000000  
gas: 6000000  
gasLimit: 3000000

Whats the difference between gasPrice - gasLimit and gas?  
Do i need all 3 or is "gas" enough?  
Or whats the best Config?

Hope anything can clear my mind and help me, thank you 🙂
