Could not find Ownable.sol file @openzeppelin/contracts/access/Ownable.sol

:computer: Environment

Truffle v5.1.32

:memo:Details

I restructured a code base and tried testing the contract with command line truffle test, but I got a compilation error complaining about imported file import “@openzeppelin/contracts/access/Ownable.sol”; from node_modules@opengsn\gsn\contracts\BasePaymaster.sol. I went through the node_modules and I could not find the Ownable,sol file in @openzeppelin/contracts/access/Ownable.sol

:1234: Code to reproduce

// SPDX-License-Identifier:MIT
pragma solidity ^0.6.2;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/IPaymaster.sol";
import "./interfaces/IRelayHub.sol";
1 Like

Hi @Sam-Devs,

That import looks correct. What version of OpenZeppelin Contracts are you using?

The file on GitHub is: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.1.0/contracts/access/Ownable.sol

I installed the current version of OpenZeppelin Contracts (v3.1.0) using

npm i @openzeppelin/contracts

I could then compile the following contract:

MyContract.sol

// SPDX-License-Identifier:MIT
pragma solidity ^0.6.2;
pragma experimental ABIEncoderV2;

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

contract MyContract is Ownable {
    
}

I installed @openzeppelin/contracts v2.4.0

1 Like

Hi @Sam-Devs,

OpenZeppelin Contracts 2.x uses Solidity 0.5 and has a different directory structure for some contracts. Ownable.sol in 2.x is in an ownership directory.

https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.4.0/contracts/ownership/Ownable.sol

Given that you are using Solidity 0.6 in your pragma you should use OpenZeppelin Contracts v3.x which supports Solidity 0.6.

Hi @Sam-Devs,

I just wanted to check that you were able to resolve?

Thank you for reaching out.
I am just reading through your responses now. I will try it out and revert to you.

1 Like

Hi @Sam-Devs,

Just wanted to check if you had any more questions?

1 Like