0

I have solidity project with files like

pragma solidity ^0.5.0;

import "openzeppelin-solidity/contracts/ownership/Ownable.sol";

When I try to compile, I get error on not installed library

npx hardhat compile                
Error HH411: The library openzeppelin-solidity, 
imported from contracts/....sol, is not installed. 
Try installing it using npm.

I have tried installing

npm install @openzeppelin/contracts

and v3.1.0 that is proper match for solidity v0.5.0

npm install @openzeppelin/contracts@3.1.0

But get the same error.

So what is this openzeppelin-solidity library, and how to install it?

1

Your code is wrong. The correct code should look like this.

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

There is no such library openZeppelin-solidity, The correct library is@openZeppelin/contracts

2
1

Thanks to @zmy comment, pointing to https://www.npmjs.com/package/openzeppelin-solidity.

2.3.0 is earliest version on npm registry as "@openzeppelin/contracts"
https://www.npmjs.com/package/@openzeppelin/contracts
openzeppelin-solidity has older versions
https://www.npmjs.com/package/openzeppelin-solidity

So installation should be like

npm i openzeppelin-solidity@2.2.0   

and version in range 2.1.0-2.5.1 (for solidity v0.5.0)

2.1.0 is first version to target solidity v0.5.0 https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/CHANGELOG.md#210-2019-01-04
3.1.0 is Last openzeppelin-contracts version to work with solidity v0.5.0 https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/CHANGELOG.md#320-2020-09-10
3.0.0 (2020-04-20) AccessControl: new contract for managing permissions in a system, replacement for Ownable.
so Ownable is not available since v3.0.0
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/CHANGELOG.md#300-2020-04-20
Latest is v4.2.0 (2021-06-30), requires solidity 0.8.0 since v4.0

1
  • Very good. You explained it in great detailđź‘Ť
    – zmy
    Jul 20 at 9:26

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.