1

I am using geth on a private chain. I have a Solidity function on a contract as follows:

function check()  public constant returns (string) {

    // if caller is not who it should be don't do anything
    if ( msg.sender != expectedSender )
                return;

    // if caller is expected return some information
    return someInformation;

}

I have the contract deployed and instantiated and call the method at the geth console like:

myContract.check();

I get an empty string , "", back when I make this call from the geth console. I unlocked an account with personal.unlockAccount() using the account expected for "expectedSender" but the msg.sender test still does not work.

Should this have worked? How do I make sure I call this function in the context of the correct account?

1

You can set the eth.defaultAccount For which you want the contract to be executed.

Your expectedSender is still not visible to us. So, We don't know what is that, but in most cases if it is used as the owner of the contract, then it is the account which published it. Check what account published it. You can see the transaction log from your console.

You can check the number of accounts you have by

personal.listAccounts;

And see which of the address matches from the transaction log

0

You can use myContract.call.check();. This will call it only on your node though and it will not be mined. For executing on the Blockchain you need to send a transaction to the call function

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.