0

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!

0

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...!

  • 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: <your account address>}) – Abhishek Jul 28 '17 at 5: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 6: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 8: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 8:29
  • Good point to note it down. – Abhishek Jul 28 '17 at 8:34

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.