Whenever I try to compile my solidity contract, the error ParserError: Source \"@OpenZeppelin/contracts/math/SafeMath.sol\" not found: File import callback not supported
gets thrown.
pragma solidity ^0.7.0;
import "@OpenZeppelin/contracts/token/ERC20/ERC20.sol";
import "@OpenZeppelin/contracts/math/SafeMath.sol";
Any ideas what could be causing this?
Just change the import to @openzeppelin/contracts/access/Ownable. sol and it will work in both Remix and vscode-solidity (with vscode extension you of course have to install the package using npm).
OpenZeppelin is an open-source framework to build secure smart contracts. OpenZeppelin provides a complete suite of security products and audit services to build, manage, and inspect all aspects of software development and operations for decentralized applications.
The import statement in Solidity is pretty simple, just point to the source file of the contract you want to import. // File: Contract_A. sol pragma solidity ^0.8. 0; import './Contract_B.
Make sure you opened VS Code in the root directory of the project.
In my case, this is how my VS Code directory looked like when I get that same error.
projects
|___MyContract
|__contracts
|__Contract.sol
Reopening VS Code in the MyContract
directory fixes it.
MyContract
|__contracts
|__Contract.sol
I have the same problem right now. I'm using truffle+node and I fixed it modifying the import path to a relative path, for example,
pragma solidity ^0.7.0;
import "../node_modules/OpenZeppelin/contracts/token/ERC20/ERC20.sol";
import "../node_modules/OpenZeppelin/contracts/math/SafeMath.sol";
I'm not 100% sure why this happen but I hope I helped you.
After installing OpenZeppelin close your IDE and re-open it.
For some environments, SafeMath has a different path
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
Make sure you installed openzeppelin
npm install --save @openzeppelin/[email protected]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With