Ganache-cli: Getting "out of gas" for non-zero integers

Created on 6 Mar 2017  路  1Comment  路  Source: trufflesuite/ganache-cli

If I attempt to use a parameter that is of type uint64 or int8 and not 0 then I run out of gas.

Expected Behavior



Passing in and using a non-zero integer should not run out of gas.

Current Behavior



When storing a non-zero integer the transaction comes back with a Runtime error of "out of gas".

Steps to Reproduce (for bugs)


  1. Solidarity contract:
pragma solidity ^0.4.7;

contract Test {
  mapping (bytes32 => Trip) Trips;
  bytes32[] TripsByIDs;
  struct Trip {
    bytes32 id;
    uint64 start;
    uint64 stop;
  }
  function newTrip(bytes32 id, uint64 start, uint64 stop) {
    if (Trips[id].id == bytes32(0x0)) {
      Trips[id].id = id;
      Trips[id].start = start;
      Trips[id].stop = stop;
      TripsByIDs.push(id);
    }
  }
  function getTrips() constant returns (bytes32[]) { return TripsByIDs; }
}
  1. Use truffle migrate --reset to deploy
  2. Node to call and execute the newTrip function:
let fs = require('fs');
let Web3 = require('web3');
let web3 = new Web3();

let abi = JSON.parse(fs.readFileSync('test.abi', 'utf8'));
let contract = web3.eth.contract(abi).at('<address>');
web3.eth.defaultAccount = web3.eth.accounts[0];

console.log(contract.newTrip("0x01", 100, 150));
  1. testrpc output:
  Transaction: 0xfd355fd7a11fed9a16222bc378e387b7b9bdcf191b691065e0b9c68d2c1c9195
  Gas usage: 0x015f90
  Block Number: 0x56
  Block Time: Mon Mar 06 2017 10:04:17 GMT-0700 (Mountain Standard Time)
  Runtime Error: out of gas

If you rerun the node with console.log(contract.newTrip("0x01", 0, 0)); then contract executes successfully and I can call getTrips and see that the trip was added. So far any (u)int size I've tried has failed for non-zero values. All seem to work if I pass in zeroes or if I pass in a non-zero value but do not use that parameter (for example if in the solidity contract I don't use the stop parameter then I can pass in any value for stop).

Context



This is just a fundamental contract function call with web3.

Your Environment

  • Version used:
    [email protected]
    [email protected]
  • Environment name and version (e.g. PHP 5.4 on nginx 1.9.1): Node 7.6.0
  • Server type and version: Laptop
  • Operating System and version: Win 10 x64
  • Link to your project: N/A

Most helpful comment

Well... crap. Nobody told me I had to specify how much gas to use in a function call.

console.log(contract.newTrip("0x01", 100, 150, { gas: 200000 }));

Fixed my issue. It makes complete sense that I should have to do this so that nobody can chew through my ether. Ethereum tutorials kind of suck.

>All comments

Well... crap. Nobody told me I had to specify how much gas to use in a function call.

console.log(contract.newTrip("0x01", 100, 150, { gas: 200000 }));

Fixed my issue. It makes complete sense that I should have to do this so that nobody can chew through my ether. Ethereum tutorials kind of suck.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

juanfranblanco picture juanfranblanco  路  3Comments

kumavis picture kumavis  路  3Comments

gskerry picture gskerry  路  3Comments

SCBuergel picture SCBuergel  路  5Comments

varasev picture varasev  路  3Comments