1

I have a setup where no accounts exist on a local node and communication with contracts is done by creating raw transactions with Web3 (signed in code and not by user or node).

On the contracts there are permissioned constant getter functions. EG

function getSomething() public onlyOwner constant returns(bool) {
    return something;
}

I understand it is easy to use contract.methods.getSomething.call() with Web3 but that would require an unlocked account on the local node.

It is also possible to make "calls" with web3.eth.call(obj) but only with raw unsigned transactions.

How would I make a call with a signed transaction?

  • why do you need onlyOwner? This is a constant function, so anyone can get the return value anyways, even if he's not the owner. It only takes a little more effort than without onlyOwner. – mafrasi2 May 15 '18 at 13:45
  • @mafrasi2 Are you sure about that? When I tried, the modifier for was observed and was unable to retrieve a value. When the modifier was removed it returned a value. What do you mean by "it takes a little more time" - what would be done to bypass permission? – fooboo May 16 '18 at 6:10
  • Yes, I am sure. Since the blockchain is public anyone can read whatever data he wants from it, including all "private" variables in your contract. It's a bit more difficult than reading public variables since the compiler generates an implicit getter function for those. For private variables you need to query the storage manually. Here is a guide on how to do this. Therefore, you can emulate constant functions with an address you don't own. – mafrasi2 May 16 '18 at 14:53
  • Just for completeness, there is one scenario, where the modifier makes sense on a constant function: when you are ok with other people reading the private variable, but want to prevent other contracts from doing so. I'm not sure where this scenario would occur in the real world though. – mafrasi2 May 16 '18 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.