0

I am trying to save string into a contract and hit this error. My contract is

pragma solidity ^0.4.18;

contract MyRecord {
    address owner;
    address guest;
    string note;

    modifier onlyOwner() {
        require(msg.sender == owner);
        _;
    }

    modifier onlyGuest() {
        require(msg.sender == guest);
        _;
    }

    function MyRecord() public {
        owner = msg.sender;
    }

    function grandPermission(address myGuest) public onlyOwner {
        guest = myGuest;
    }

    function revokePermission() public onlyOwner {
        guest = 0x0;
    }

    function setNote(string newNote) public onlyGuest {
        note = newNote;
    }
}

And calling setNote() using below

 let myContract = this.state.web3.eth.contract(this.state.abi).at(this.state.selected_deployadd);
        let trans = myContract.setNote(this.state.value, {from: this.state.address}, function(error, results){
            if(error) {
                console.log('setNote error ', error);
            }                
            else {
                console.log('setNote success ', results);
            }
        });

I use Ganache as my testrpc, everything looks fine even value been set into note and transaction been generated(identified by Ganache as "CONTRACT CREATION" instead of "CONTRACT CALL" which confuse me). Besides, "invalid opcode" been returned without any further information. BTW, is there a way I can debug my contract?

I am new to solidity, could someone help.

UPDATE: I tried my contract on Remix and it works fine, still struggle with Ganache and need help.

  • did you call the 'grandPermission' method before this instruction? looks like your methods will be executed only if the sender has received the guest grant – mirg Apr 13 '18 at 14:10
  • @mirg Yes, I did and calling grandPermission() causes a "CONTRACT CALL" transaction saved in Ganache – Bing Lan Apr 13 '18 at 22:17
1

I cannot see the particular cause of your issue, but to answer your second question, the best way to debug your contract is to use Remix. It has built in tools for debugging, deploying (to VM or Test and Main Nets) and testing contracts and is entirely within the browser.

  • It turns out everything is fine on Remix so I assume it's Ganache API issue or something else. – Bing Lan Apr 14 '18 at 10:47

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.