0

I have a contract which has this function:

function registerSensor(bytes32 name, bytes32 unit, bytes32 location) returns (bool success)
{
    sensors[msg.sender].exists = true;
    sensors[msg.sender].name = name;
    sensors[msg.sender].unit = unit;
    sensors[msg.sender].location = location;
    addresses.push(msg.sender);
    return true;
}

If I call this function in the truffle-console with this command:

Svd.then(function(instance) {return instance.registerSensor("Miner", "MH/s", "Desk"); })

then everything works fine, the sensor gets added to the addresses-array.

If I try to do the same in the geth-console then nothing happens, the sensor doesn't get added to the addresses-array. I can see the transaction is send and I also get a transaction id.

var svd = web3.eth.contract([{"constant":true,"inputs":[{"name":"addr","type":"address"}],"name":"getSensorData","outputs":[{"name":"data","type":"bytes32[]"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"getSensorAddresses","outputs":[{"name":"addr","type":"address[]"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"name","type":"bytes32"},{"name":"unit","type":"bytes32"},{"name":"location","type":"bytes32"}],"name":"registerSensor","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"addr","type":"address"}],"name":"getSensorMetaData","outputs":[{"name":"name","type":"bytes32"},{"name":"unit","type":"bytes32"},{"name":"location","type":"bytes32"}],"payable":false,"type":"function"},{"inputs":[],"payable":true,"type":"constructor"}]).at('0x27517492524152c925061648b15d78d451bbd04b')

svd.registerSensor("Node 1", "C", "Desk", {from: web3.eth.accounts[0]}, function(err, result) {
   console.log(err);
   console.log(result);
})

Here is the output of the console: enter image description here

Am I missing something?

0

Ok the problem was that I didn't defined a gas-limit, so after adding the max amount of gas it is finally working:

svd.registerSensor("Node 1", "C", "Desk", {from: web3.eth.accounts[0], gas:3000000})

:), seems like truffle adds the gas-limit automatically

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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