0

I have been struggling with this exception and am literally stuck in development: "Error: Returned error: VM Exception while processing transaction: out of gas"

I removed all the code and just trying to set a simple struct with one string with some modifier checks and deploying using truffle develop to localhost.

The problem is that basic uints and single strings are setting and working, but If i make the function by just adding a few modifiers, the function fails with out of gas exception.

How can we develop if even simple functions fail out of gas?

UPDATE: the code below

I have a simple smart contract deployed on the local truffle env using migrate. I am using react-components package to work with the smart contract.

So my issue is that simple getters and setters are working, but when I try to run a method with 2-3 arguments I am getting this exception.

My truffleconfig is as follows:

module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // to customize your Truffle configuration!
  contracts_build_directory: path.join(__dirname, "app/src/contracts"),
  networks: {
    develop: { // default with truffle unbox is 7545, but we can use develop to test changes, ex. truffle migrate --network develop
      host: "127.0.0.1",
      port: 8545,
      network_id: "*",
      gas: 6921975,
      gasPrice: 25000000000
    }
  },
  solc: {
        optimizer: {
            enabled: true,
            runs: 200
        }
    }
};

And in my react component I am calling like this:

  <div className="section">
    <h2>Testing Poni</h2>
    <p>
      This is a initial test to create Poni
    </p>
    <p>
      <strong>Stored Value: </strong>
      <ContractData
        drizzle={drizzle}
        drizzleState={drizzleState}
        contract="PoniOwnership"
        method="getMyPonies"
      />
    </p>
    <ContractForm drizzle={drizzle} contract="PoniOwnership" method="createPoni" />
  </div>

My solidity functions are like this:

function createPoni(string memory _code, string memory _imgLink) public onlyOwner poniIsUnique(_code){

    uint randDna = _generateRandomDna(_code);

    //!!pass imgHash here also later
    _createPoni(_code, _imgLink, randDna);
  }

function _createPoni(string memory _code, string memory _imgLink, uint _dna) private {

    uint id = ponies.push(Poni(msg.sender, _code, _imgLink, _dna, 0, true)) - 1;

    poniToOwner[id] = msg.sender;
    codeToId[_code] = id;
    ownerPoniCount[msg.sender] = ownerPoniCount[msg.sender].add(1);

    emit NewPoni(id, _code, _imgLink, _dna);
  }

struct Poni {
    address owner;
    string code;
    string imgLink;
    uint dna;
  }

I have tried to additionally send gas from the drizzle react-component as options are given here: https://www.trufflesuite.com/docs/drizzle/react/react-components, but it throws errors saying function is not payable. I am not able to figure out how to deal with this exception.

UPDATE i was able to deploy smoothly to the rinkeby network, and create my token using the console and check for the value being inserted properly. I am at a loss understanding why truffle ganache wont work and keep throwing this gassy message!

8
  • Are we supposed to guess what your code and environment setup look like??? Apr 25, 2020 at 14:29
  • @goodvibration you could have literally guessed it. It mostly truffle react box boiler plate code, and I have just deployed a simple contract to set the values
    – srinivas
    Apr 25, 2020 at 14:50
  • Hahaha, right. I could have guessed those 400 lines you just added in your question. Apr 25, 2020 at 14:51
  • Exactly which function are you trying to execute which throws this exception, and how exactly are you calling it (show the code in which you call it). Apr 25, 2020 at 14:53
  • 1
    @Ismael surprisingly i was able to deploy smoothly to the rinkeby network, and create my token using the console and check for the value being inserted properly. I am at a loss understanding why truffle ganache wont work.
    – srinivas
    Apr 26, 2020 at 10:36

0

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.

Browse other questions tagged or ask your own question.