Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 4: TypeError: Overriding modifier is missing "override" specifier. / #86

Open
akirpach opened this issue Feb 14, 2022 · 1 comment

Comments

@akirpach
Copy link

akirpach commented Feb 14, 2022

At the beginning of chapter 5 I try to compile previously added code in chapter 4 and receive the following output:
image

Here's my Greeter.sol code:
`pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";

contract Greeter is Ownable {
string private _greeting = "Hello, World!";
address private _owner;

constructor() {
    _owner = msg.sender;
}

modifier onlyOwner() {
    require(
        msg.sender == _owner,
        "Ownable: caller is not the owner!"
    );
    _;
}

function greet() external view returns(string memory) {
    return _greeting;
}

function setGreeting(string calldata greeting) external {
    _greeting = greeting;
}

function owner() public view returns(address) {
return _owner;
}

} `

@MarcoBerlot
Copy link

If you import Ownable from Zeppelin, there should be no need for you to write your own onlyOwner() modifier. Here's a working example

pragma solidity >= 0.4.0;

import "@openzeppelin/contracts/access/Ownable.sol";

contract Greeter is Ownable {

  string private _greeting = "Hello, World!";

  function greet() external view returns(string memory) { return _greeting; }

  function setGreeting(string calldata greeting) external onlyOwner {
    _greeting = greeting;
  }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants