13

I am trying out Remix as an IDE. However, I'm using the excellent open-zeppelin library for development. Is there any way to include all the files from open-zeppelin in the build path for Remix without pasting them all in there?

I have tried importing a local directory, but since my normal build tool is Truffle, the Remix compiler doesn't pick up the node_modules directory. I tried copying the open-zeppelin directory into the contracts directory, but still my imports won't work. They work if I prefix my paths "./", but I'd rather not do that, since I would have to do it in every single open-zeppelin file.

4 Answers 4

10

The easiest is to use remixd to share your build directory with remix. Here are indication how to configure it Accessing a shared folder in Remix IDE using Remixd.

Another option is to use the remix feature that allows importing directly from github, so you do not need the openzeppelin files.

pragma solidity ^0.4.15;

import "github.com/OpenZeppelin/zeppelin-solidity/contracts/ownership/Ownable.sol";

contract BasicToken is Ownable {
    function () public payable {
    }

    function withdraw(uint amount) public {
        if (amount <= this.balance) {
            msg.sender.transfer(amount);
        }
    }
}
3
  • 3
    I'm using a shared folder with remixd. The point is, I don't want to rewrite all my import statements in order to be able to work in Remix. My code (and the zeppelin code) already contains import statements of the type import "zeppelin-solidity/contracts/crowdsale/CappedCrowdsale.sol";. I'd like the import statements to stay that way. Commented Nov 28, 2017 at 9:20
  • URL is dead unfortunately
    – Emobe
    Commented Dec 31, 2019 at 12:25
  • @Emobe Remix has changed a lot from two years ago. The new URL seems to be remix-ide.readthedocs.io/en/latest/remixd.html.
    – Ismael
    Commented Jan 1, 2020 at 2:16
3

Have you tried Patricio Palladino's truffle-flattener?

Truffle Flattener concats solidity files developed under Truffle with all of their dependencies.

This tool helps you to verify contracts developed with Truffle on Etherscan, or debugging them on Remix, by merging your files and their dependencies in the right order.

2

Yes it's possible just use:

pragma solidity ^0.4.24;

import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/ownership/Ownable.sol";

contract SimpleContract is Ownable {

}

The package zeppelin-solidity mentioned above is deprecated

1
  • Problem is the openzeppelin-solidity contracts import other ones and they don't use the github link. This is not a correct answer.
    – M H
    Commented Apr 17, 2019 at 2:35
0

you can import with github.

https://remix-ide.readthedocs.io/en/latest/import.html

ie:

pragma solidity ^0.7.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.4.0-solc-0.7/contracts/token/ERC20/ERC20.sol";

contract Token is ERC20 {

    constructor () ERC20("Token", "TKN") {
        _mint(msg.sender, 1000000 * (10 ** uint256(decimals())));
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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