1

In some of my getter methods I'm using msg.sender to deal with access rights. However this just gave me errors, because every single call just comes from the first account of web3.eth.accounts. My question is: In my frontend-application I have a keypair of PubK and PK, and I want to call these getter-methods under this identity.

Here some information about how I am calling my contracts methods:

var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

var abiContract = web3.eth.contract([...]);

var contract = abiContract.at(contractAddress);

And now I can call all the methods from the contract-object. For all state-changing transaction I created a method that uses raw transactions. I am just not sure of how to use these for getter-methods, because all I get returned is the transaction hash, nothing from the return-statements.

1 Answer 1

0

When you are talking about getter methods are you talking about constant/view functions? All information on the blockchain is public, restricting access to this wouldn't make a lot of sense.

Nevertheless you can specify an account you are sending from in the web3 call:

contract.method.call(params, {from:web3.account[1], value: x})
1
  • This actually resolved my problem. I don't have to use an account object, instead a public Key (aka address) is also enough. Thanks!
    – S1r_Mar71n
    Commented Jan 27, 2018 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.