1

I am trying out a very simple contract on the Rinkeby testnet. Pretty much as simple as it gets:

pragma solidity ^0.4.17;

contract Root {
    string rootHash;

    function set(string x) public {
        rootHash = x;
    }

    function get() public constant returns (string x) {
        return rootHash;
    }

}

It stores an ipfs multihash, and allows retrieving it.

The write part seems to work, using this code: https://gist.github.com/pwrstudio/6c95043ae3bb6a9aef9734a3fc8469e7

I can see that the multihash is sent to the contract, encoded as hex: https://rinkeby.etherscan.io/tx/0x4d7b98cf577d580168d24b1f61bcbc60f3f919c751624793e83dd10191ebba98

But when calling the get function I get this error:

ERROR: The returned value is not a convertible string

Relevant js code:

return new Promise((resolve, reject) => {
  const rootContract = new web3.eth.Contract(abi, CONTRACT_ADDRESS)
  rootContract.methods
    .get()
    .call()
    .then(res => console.log(res))
    .catch(e => console.log(e))
})

Any pointers on what I am doing wrong much appreciated!

3

There is a small typo in the definition of function get. You should define only the return type string in the function definition, but no variable name (x). This should make it work:

function get() public constant returns (string) {
    return rootHash;
}
| improve this answer | |
  • Thanks a lot! That did it. (Turned out I had also specified to low gas limit for the set function call, causing it to fail, but with those two problems fixed, everything works.) – Rasmus Svensson Dec 5 '17 at 14:21

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.