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

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:

    PolygonMumbai : {
      url: "", 
      accounts: [PRIVATE_KEY],

With this some Transactions not worked.

Failed Transactions:

Worked Transactions:

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:

  matic: {
      url: "",
      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?

// Contract based on
// 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)

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

       return newItemId;
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)

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 :slight_smile: