Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Getting "out of gas" for non-zero integers #273

Closed
coreyog opened this issue Mar 6, 2017 · 1 comment
Closed

Getting "out of gas" for non-zero integers #273

coreyog opened this issue Mar 6, 2017 · 1 comment

Comments

@coreyog
Copy link

coreyog commented Mar 6, 2017

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:
    ethereumjs-testrpc@3.0.3
    truffle@3.1.2
  • 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
@coreyog
Copy link
Author

coreyog commented Mar 6, 2017

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant