Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;

like image 774
Brennan Avatar asked Mar 06 '20 18:03

Brennan


2 Answers

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";
like image 189
Jeremy Meek Avatar answered Sep 30 '22 14:09

Jeremy Meek


This is no longer needed with Solidity version 8

like image 29
Brennan Avatar answered Sep 30 '22 13:09

Brennan