1

This is the smart contract I'm trying to interact with, verified on etherscan.io, and reproduced here:

pragma solidity ^0.4.13;

// This contract demonstrates a simple non-constant (transactional) function you can call from geth.
// increment() takes no parameters and merely increments the "iteration" value. 

contract Incrementer {
    uint iteration;

    function Incrementer() {
        iteration = 0;
    }

    function increment(uint count) {
        iteration += count;
    }

    function getIteration() constant returns (uint) {
        return iteration;
    }

}

The commands I'd like to use to call it are:

Incrementer.deployed().then(function(instance) {
  meta = instance;
  return meta.increment(1);
})

to increase the iteration variable, and:

Incrementer.deployed().then(function(instance) { 
    meta = instance; 
    return meta.getIteration(); 
}) 

to verify the result.

Those are commands that work on the truffle console with testrpc, but now I'm trying to issue those commands through geth to the ropsten testnet.

I've tried to adapt them to this purpose according to the answer to this question, like so:

var contractAbi = eth.contract([{"constant":false,"inputs":[{"name":"count","type":"uint256"}],"name":"increment","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"getIteration","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"}]);
var myContract = contractAbi.at(0x8705C513da621a16fd1dEFc9dE8aE7CDEAD01Fb8);
var getData = myContract.getIteration.getData(1);
web3.eth.sendTransaction({to:0x8705C513da621a16fd1dEFc9dE8aE7CDEAD01Fb8, from:0xd7a9a61a480d458a1181e0563b07f944df4489a6, data: getData});

but it didn't work, the result was this:

Error: invalid address
    at web3.js:3879:15
    at web3.js:3705:20
    at web3.js:4948:28
    at map (<native code>)
    at web3.js:4947:12
    at web3.js:4973:18
    at web3.js:4998:23
    at <anonymous>:1:1

The output of getData rendered in this way:

> getData

"0xfc2c3e08"

See the console output here:

enter image description here

What is the correct procedure to adapt those commands to execute a function on the ropsten tesnet using geth console?

2

It seems to work if you put the addresses in quotes:

> var contractAbi = eth.contract([{"constant":false,"inputs":[{"name":"count","type":"uint256"}],"name":"increment","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"getIteration","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"}]);

undefined

> var myContract = contractAbi.at("0x8705C513da621a16fd1dEFc9dE8aE7CDEAD01Fb8");

undefined

> var getData = myContract.getIteration.getData(1);

undefined

> personal.unlockAccount(eth.coinbase, 'hunter2')

true

web3.eth.sendTransaction({to:"0x8705C513da621a16fd1dEFc9dE8aE7CDEAD01Fb8", from:"0xd7a9a61a480d458a1181e0563b07f944df4489a6", data: getData});

"0xb8d229d46500681f08ae7286359dc052036d14e2814bbf9bca6ea217b904345b"

and so I guess the result of the transaction is here on etherscan.io:

enter image description here

It says that I called the function getIteration(), and it's true, I did do that.

BUT

be forewarned, this is not immediately relevant to the question in the OP...

dig this strange situation:

when I call the increment function with a value of 1, i.e.:

var getData = myContract.increment.getData(1);

I get this:

Function: increment(uint256 count)

MethodID: 0x7cf5dab0
[0]:0000000000000000000000000000000000000000000000000000000000000001

ok, fair enough- the rub is- when I call it with 666, I get:

Function: increment(uint256 count)

MethodID: 0x7cf5dab0
[0]:000000000000000000000000000000000000000000000000000000000000029a

when I would have expected 667.

What is that result? some kind of strange hex encoding?

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.