Hello. I’m trying to follow this tutorial, in order to get familiar with the openzeppelin SDK. I have been able to develop, deploy and mint an ERC-721 token using the truffle suite, but I felt like giving this other toolbox a try.
I have been able to compile the simple version of the Box contract.
// contracts/Box.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
contract Box {
uint256 private value;
// Emitted when the stored value changes
event ValueChanged(uint256 newValue);
// Stores a new value in the contract
function store(uint256 newValue) public {
value = newValue;
emit ValueChanged(newValue);
}
// Reads the last stored value
function retrieve() public view returns (uint256) {
return value;
}
}
However, whenever I try to add dependencies I get compilation errors. I would like to include the “Ownable.sol” file from the OpenZeppelin library, to follow the tutorial, but it is giving me the following error.
// contracts/Box.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
// Import Ownable from the OpenZeppelin Contracts library
import "@openzeppelin/contracts/access/Ownable.sol";
// Make Box inherit from the Ownable contract
contract Box is Ownable {
uint256 private value;
event ValueChanged(uint256 newValue);
// The onlyOwner modifier restricts who can call the store function
function store(uint256 newValue) public onlyOwner {
value = newValue;
emit ValueChanged(newValue);
}
function retrieve() public view returns (uint256) {
return value;
}
}
It is weird, because the error is about a dependency of the “Owner.sol” contract, if I am not mistaking, which means that Owner.sol is correctly being imported into Box.sol.
I have installed the contracts with:
npm install --save-dev @openzeppelin/contracts
Even the intellicense plugin in Visual Studio Code can find the path to the file, but the compiler does not.
Environment
I’m using Windows 8.1 (I’ve seen there are a lot of problems with windows) and the version 2.8.2 of the SDK.
Code to reproduce
All of the code being used is exactly the same as the one described in the tutorial.