I'm a newb dev and want to play with smart contracts, and was trying to figure this out. Ive installed truffle and openzeppelin, everything seems to check out, but in Mist I still get an error when I try to import Math.sol saying it can't be found, what do I do?

  • Please provide code example of how you are trying to import Math.sol. – Roman Frolov Aug 20 '18 at 20:01
  • import "openzeppelin-solidity/contracts/math/Math.sol"; – Future Blok Aug 20 '18 at 20:26
  • check the existent of the openzeppelin-solidity folder under node_modules to ensure that it was installed properly on your local machine – Ha ĐANG Aug 21 '18 at 3:41

Here are the full steps starting from a blank truffle project. You could replace truffle init with truffle unbox <package> if you want to start from a Truffle box.

  1. Create a new directory
  2. truffle init: initialize truffle in the directory
  3. truffle install zeppelin: install open-zeppelin using ETH Package Manager

A new folder will be created called installed_contracts which contains all the files.

You can import the Math.sol library by adding this line in your contract in the contracts folder:

import "installed_contracts/zeppelin/contracts/math/Math.sol";
| improve this answer | |
  • Works, except you probably need to give a relative path, at least I had to, as in import "../installed_contracts/zeppelin/contracts/math/Math.sol"; – riper Sep 4 '18 at 10:59
  • Using the latest version of truffle with visual studio code, I did not need to specify a relative directory, but I am glad it worked one way or another. – Shawn Tabrizi Sep 4 '18 at 17:03

Take a look at the section about installing and using the libraries on the official OpenZeppelin repo. There is a guide to correctly import and use libraries, such as Math.sol.

See below for an example:

import 'openzeppelin-solidity/contracts/ownership/Ownable.sol';

contract MyContract is Ownable {
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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