0

Is there any EIP that specifies how to implement function in contract, that let's you call any other function as contract owner, with provided signature?

I don't want to reinvent wheel.

For example:

I want to create token contract, in which any address with ethers (for gas) can push transfer tokens transactions, as other address (sender) with its signature in which there may not be any ethers for gas.


  function transferFrom(address recipient, uint256 amount, uint8 _v, bytes32 _r, bytes32 _s) public {
    address recipient = msg.sender;
    bytes32 hash = keccak256('Transfer tokens:', recipient, amount);
    address caller = ecrecover(hash, _v, _r, _s);
...
  }

I need something like this.

My question is. Is there any EIP for that or maybe more generic EIP not only for token transfers?

3
  • I think you can use modifier for that. – Alireza Oct 12 '20 at 15:48
  • Why would you need an EIP for a single state variable indicating who the owner is, and a simple check of whether or not the caller is also the owner??? BTW, you technically don't need keccak nor ecrecover here, so you as well remove those two from the tagging of this question. – goodvibration Oct 12 '20 at 15:52
  • I didn't explained my problem well. I edited post. I know what ecrecover is and I am sure that contract needs that function, hash function also. – gkucmierz Oct 12 '20 at 20:12
2
contract Ownable {

  address public owner;

  modifier onlyOwner {
    require(msg.sender == owner, "Ownable: You are not the owner, Bye.");
    _;
  }

  constructor () public {
    owner = msg.sender;
  }
}

contract Owned is Ownable {

  function doSomething() public onlyOwner {
    // caller is the owner if they got this far.
    // carry on
  }
}

See the @OpenZeppelin/contracts access control contracts for a well-crafted implementation of this solution.

Hope it helps.

3
  • 1
    It's not an EIP though, just a common implementation which has become a kind of "ad hoc standard". – goodvibration Oct 12 '20 at 17:39
  • BTW, OZ have changed address public owner to internal and later to private quite a long time ago (v2.0.0 if I remember correctly). The reason for it being that any inheriting contract (for example, contract Owned in your answer) has the permission to (undesirably) change the value of owner and damage the intended functionality of it. – goodvibration Oct 12 '20 at 17:40
  • That's true. My example is idiomatic. The OZ implementation addresses the subtleties that would take too long to explain. – Rob Hitchens Oct 12 '20 at 17:53

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.