How to correctly import SafeMath.sol into contract
This has been a problem I've been dealing with for a while now. My temporary solution has been to create a SafeMath.sol file in my Contracts directory and directly import it from there. However, I've been looking for a 'clearer solution' to this... Old way seemed to be directly importing it from a GitHub link, as seen in some repos and other stack overflow posts like such
However, the proper way do this seems to be installing the corresponding oz package (@openzeppelin/contracts-ethereum-package) and importing the file directly into the needed contract i.e.
import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
However, using VSCode, I still get the error Source "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol" not found: File import callback not supported
That said, how can I properly import SafeMath?
EDIT: I am using pragma solidity ^0.6.0;
Solution 1:
I looked through the node_modules
for the package @openzeppelin/contracts
. Here is the current correct import path as of posting:
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
Solution 2:
This is no longer needed with Solidity version 8
Solution 3:
path is different in v 3.0 documentation
I used this:
import "@openzeppelin/contracts/math/SafeMath.sol";
Instead of this:
import "@openzeppelin/contracts/utils/math/SafeMath.sol";