How do I ensure that the function is performed by the owner of the account using web3.js whose instance is used to call the function, I am using ganache and I have my private keys for account .

1 Answer 1


To do that you must verify the transaction's sender in your Smart Contract. For example:

function someFunction () {
    // if who sends transaction is different to 0xbb2048f1...
    // rejects transaction and refunds ETH sended.
    require(msg.sender != 0xbb2048f1be4c6e794b20502437d09552b4bc07f0);
    // if msg.sender == 0xbb2048f1... enter here

You can do it with Solidity modifiers

modifier onlyOwner {
    require(msg.sender == 0xbb2048f1be4c6e794b20502437d09552b4bc07f0);

So now you can verify who sends transactions using onlyOwner modifier

function doSomething() onlyOwner {
    // Only if sender is equals to 0xbb2048f1... enter here
    // Else do a revert(); and refund eth sended
  • but here it ensures that the contract is called from a specific account and not the person who called the function owns that account. I want to use my private key , only the owner of the account who has the key can call functions using the account . Jun 12, 2018 at 12:29
  • msg.sender proves they have signed the transaction from that account, therefore they have the private key for that account. This is as close as you can get to proving they own the account. Feb 13, 2019 at 19:44

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.