If I attempt to use a parameter that is of type uint64 or int8 and not 0 then I run out of gas.
Passing in and using a non-zero integer should not run out of gas.
When storing a non-zero integer the transaction comes back with a Runtime error of "out of gas".
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; }
}
truffle migrate --reset to deploynewTrip 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));
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).
This is just a fundamental contract function call with web3.
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.
Most helpful comment
Well... crap. Nobody told me I had to specify how much gas to use in a function call.
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.