0

I am currently working on a smart contract and using modifiers. I want to restrict access to a function only to a single account. I can do this with 'msg.sender' but to my knowledge this limits only to the account that deployed the contract. I want only the account 'web3.eth.accounts[2]' to access the function. Is this possible in solidity?

  • require(msg.sender == address_you_want); – OWADVL Nov 6 '18 at 10:25
0

Msg.sender actually is the address of the caller of the function. This can be anyone: either a smart contract or an external account. You can hard-code in your smart contract which addresses you want to be able to call certain functions, or specify them using the constructor.

|improve this answer|||||
0

Restricting access is a common pattern for contracts. Note that you can never restrict any human or computer from reading the content of your transactions or your contract’s state. You can make it a bit harder by using encryption, but if your contract is supposed to read the data, so will everyone else.

Take a look documentation https://solidity.readthedocs.io/en/v0.4.24/common-patterns.html#restricting-access

|improve this answer|||||

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.