1

I'm trying to write a contract that has a string that can be modified/updated by the owner later on. I tested it in Remix and it works perfectly. But when I deploy it to my private blockchain, I get errors. Any ideas? Or is there at least a reasonable way to debug the code? These errors seem to be useless!

pragma solidity ^0.4.13;

contract c5 {
    uint currentVersion;
    string command;
    address owner;

    //Constructor is automatically executed upon creation:
    function c5(){
            currentVersion = 1;
            command = "test1";
            owner = msg.sender;
    }

    function update(uint input){
            if(msg.sender != owner) return;
            currentVersion = input;
    }

    function query() constant returns (string){
            return command;
    }

    function version() constant returns (uint){
            return currentVersion;
    }
}

This is the error I get in the geth console:

> c5.query()
"test1"
> c5.version()
1
> c5.update("4")
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 web3.js:4061:16
at apply (<native code>)
at web3.js:4147:16

Are these strings indeed editable? or do I need to submit a new contract with the new string and direct queries to it via an updated address via DELEGATECALL:

Upgradeable smart contracts

Thanks in advance for any ideas!

1 Answers1

1

As update function in your contract is a setter, it would require an account address to execute.

In Remix it automatically sets a default account.

Try to set the default account and then execute:

web3.eth.defaultAccount = web3.eth.accounts[0]

Hope this helps...!

Abhishek
  • 800
  • 4
  • 15
  • Error is mainly due to lack of account address.You need to some how attach an account to your call. Can you give a try with c5.update("4"{from: }) – Abhishek Jul 28 '17 at 05:37
  • Do you mean like this? > c5.update("4"{from:"0x6dd4530a254de371110f88322a67c7d77dc60790"}) I tried several variants of that with quotes and commas added as well but always got errors like this: (anonymous): Line 1:14 Unexpected token { (and 2 more errors) – Jonny Sweeny Jul 28 '17 at 06:54
  • It should be working. You can try compiling code again and then test because there doesn't seems to be anything wrong in the code. – Abhishek Jul 28 '17 at 08:13
  • I think I figured out what you guys were getting at; now the errors are gone and I get a confirmation hexadecimal string of some type, after trying this: > c5.updateV(44321,{from: eth.accounts[0]}) "0x46e2ad3a25b00aa12624093492c1b84ee28b9f4aee6c632cca363d4d756c72cc"

    Note to future persons, that you won't notice the updated value via the query command until after a block has been mined. `> miner.start(1) null

    miner.stop()

    true

    c5.query()

    44321`

    – Jonny Sweeny Jul 28 '17 at 08:29
  • Good point to note it down. – Abhishek Jul 28 '17 at 08:34
  • both of these solutions work but the running of web3.eth.defaultAccount = web3.eth.accounts[0] by itself first in the console is the cleanest and easiest. – Jonny Sweeny Jul 29 '17 at 02:20
  • @Abhishek - where do we run this web3 command? it has to be part of .sol file? Can we do something with eris-contracts – Varun Aug 14 '17 at 07:35
  • As web3 is a javascript library for interacting with ethereum, you can run the web3 commands on any javascript console or file. I am not sure if it works for eris contracts. – Abhishek Aug 15 '17 at 09:58