3

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/[email protected]

But get the same error.

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

4 Answers 4

3

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 [email protected]   

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, 2021 at 9:26
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
0

I coded the import by hand and typo'd it showing this error. Correcting the spelling made it work again as it was trying to find something that didn't exist.

0

For the Openzeppelin contract installed that with --force and it works fine.

npm install @openzeppelin/[email protected] --force

Also, there seems to be a versioning issue, for the latest Openzeppelin the version of solidity to be used is 0.8.20. it works for me this way

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.