I am developing an NFT using truffle, and I struggle to make my mint() function work :

function mint(uint256 tokenId) public onlyElevated whenNotPaused returns (uint256) {
    require(totalSupply() < TOTAL_SUPPLY, "Max supply reached");
    _mint(msg.sender, tokenId);
    return tokenId;

_mint() comes from openzeppelin's ERC721 contract (available on github).

When I run tests in truffle develop with truffle test, everything works fine and I have this output for a test that mints 3 tokens:

Gas used for mint : 173126
Gas used for mint : 143126
Gas used for mint : 143126

However I am now trying to deploy it on a ganache local network in order to run advanced tests. The deployment is ok, and I can connect to my contract with my client and call functions, but when I try to send the mint() transaction, I have this error :

ethBalanceBefore=EtherAmount: 99931764660000000000 wei
RPCError: got code -32000 with msg "VM Exception while processing transaction: out of gas".

I don't understand why it works fine in truffle tests and not here, so here are my questions :

  • Can the gas used for a transaction be different according to the network I deploy my contract on? I thought only the gasPrice changes.
  • Can the above error be fired because of issues not related to gas?

Update :

Here is my truffle-config.js :

module.exports = {
  compilers: {
    solc: {
      version: "^0.7.0",
  solc: {
    optimizer: {
      enabled: true,
      runs: 200,
  networks: {
    develop: {
      host: "",
      port: 8546,
      network_id: "*",
    development: {
      host: "",
      port: 7545,
      network_id: "5777",

I tried to change the gas value to 9000000000000000, but it still fails

  • Maybe paste the relevant parts of truffle config? Mar 10, 2021 at 20:28
  • I updated my post, ganache will use the development network
    – Ltei
    Mar 10, 2021 at 20:35
  • What does Ganache say about the transaction's used gas and gas limit? Mar 10, 2021 at 20:47
  • You are right it says GAS PRICE 20000000000, GAS LIMIT 90000. So I guess the answer to my first question is yes, do you have any idea why the gas price is different and so high?
    – Ltei
    Mar 10, 2021 at 20:51

1 Answer 1


The error message is correct. Your transaction is simply running out of gas.

According to the Truffle docs (https://www.trufflesuite.com/docs/truffle/reference/configuration) the default gas limit is 6721975, which would be enough for most transactions. Since you don't have anything specified in your truffle config, I assume that's the limit Truffle uses.

However, your Ganache says that the transaction gas limit is 90000 and the transaction requires around 170k of gas, therefore the transaction fails. The required amount of gas should be the same in all networks (assuming their state is the same).

You are either giving explicitly wrong gas limit for the transaction, or your Ganache is setting the gas limit (sounds unlikely). The gas price shouldn't make any difference since it's your own network.

Your Answer

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

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