Ownable.sol is not resolving ownerOnly()

I am trying to switch my contract to use the 'import "@openzeppelin/contracts/access/Ownable.sol”’, but I am getting the following error

contracts/InvoiceTracker.sol:93:9: DeclarationError: Undeclared identifier.


for this code:

  function addClient(address _clientID, string memory _name)



        noDupClient(_clientID, _name)


I have installed:

"@openzeppelin/cli": "^2.8.2",

"@openzeppelin/contracts": "^3.1.0",

"@openzeppelin/test-helpers": "^0.5.6”

Can you give me a clue as to why this is happening?

1 Like

Hi @denismp,

Welcome to the community :wave:

You could get this error if your contract isn’t inheriting from Ownable.
As well as importing, we need to inherit Ownable.

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

contract MyContract is Ownable {}

See the example in the documentation for more details:

As an aside, you may want to look at using Access Control for more finely grained control: https://docs.openzeppelin.com/contracts/3.x/access-control#role-based-access-control

Hi @denismp,

Checking that you were able to compile after inheriting Ownable?