[Ethereum] How to properly call getter methods from a specific keypair in web3

constantraw-transactionweb3js

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.

Best Answer

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})
Related Topic