1

I made a compiler script that takes all contracts in folder ./contracts/ and produces a .json for each contract, containing an ABI and Bytecode. This worked fine for a while. However, I added some ERC20 functionalities so on my Smart contract I did:

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";

This works really good in Remix cause it downloads the files for me. However now when I run my compiler.py script, I get this error.

$ python3 compiler.py 
Traceback (most recent call last):
  File "compiler.py", line 23, in <module>
    compiled_contracts = compile_files(array_of_contracts_to_compile)
  File "/home/jquintanilha/Documents/ethereum-contracts/MyEnv/lib/python3.7/site-packages/solcx/main.py", line 133, in compile_files
    stdoutdata, stderrdata, command, proc = solc_wrapper(**compiler_kwargs)
  File "/home/jquintanilha/Documents/ethereum-contracts/MyEnv/lib/python3.7/site-packages/solcx/utils/string.py", line 85, in inner
    return force_obj_to_text(fn(*args, **kwargs))
  File "/home/jquintanilha/Documents/ethereum-contracts/MyEnv/lib/python3.7/site-packages/solcx/wrapper.py", line 177, in solc_wrapper
    stderr_data=stderrdata,
solcx.exceptions.SolcError: An error occurred during execution
        > command: `/home/jquintanilha/Documents/ethereum-contracts/MyEnv/lib/python3.7/site-packages/solcx/bin/solc-v0.5.11 --combined-json abi,asm,ast,bin,bin-runtime,devdoc,opcodes,userdoc ./contracts/DoubleSigWalletFactory.sol ./contracts/Pricing.sol ./contracts/PricingFactory.sol ./contracts/DoubleSigWallet.sol`
        > return code: `1`
        > stderr:

        > stdout:
        ./contracts/DoubleSigWallet.sol:9:1: Error: Source "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol" not found: File outside of allowed directories.
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol";
^-----------------------------------------------------------------------------------------------------------^
./contracts/DoubleSigWallet.sol:10:1: Error: Source "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol" not found: File outside of allowed directories.
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
^----------------------------------------------------------------------------------------------------------^

It kind of looks like I can't import remote repositories locally to compile. Is that true?

Here is my compiler.py

import os
import json
import shutil
from os import listdir
from solcx import compile_files

path_to_contracts = "./contracts/"
array_of_contracts_to_compile = []
c_json = ""

# gets all contracts .sol in contracts dir
for f in listdir(path_to_contracts):
    if f.split('.')[1] == 'sol':
        array_of_contracts_to_compile.append(path_to_contracts+f)

#   deletes dir build + its files and creates an empty new one
if os.path.exists("build"):
    shutil.rmtree('build')
os.mkdir('build')


# compiles all contracts in folder ./contracts
compiled_contracts = compile_files(array_of_contracts_to_compile)

# for each compiled contract, create json file inside build directory
# contains abi and bytecode of each contract
for c in compiled_contracts:
    c_json = json.dumps(compiled_contracts[c],  indent=2)
    f = open(r"./build/" + str(c.split(':')[1]) + ".json", "w+")
    f.write(c_json)

and here is the beginning of my contract where it crashes:

pragma solidity ^0.5.11;

/// @title DoubleSigWallet - Allows two parties to agree on transactions before execution.
/// @author João Quintanilha 

import "./Pricing.sol";

// Import OpenZeppelin's ERC20 interface defenition
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";


contract DoubleSigWallet {
    IERC20 public DAI;

    /*
     *  Events
     */
    event NewTransaction(uint256 transactionId);
    event EndUserSigned(bool signed);
...
3
  • Note: You should only use code published in an official release of OpenZeppelin Contracts, the latest release is 2.3. When importing via GitHub on Remix you can specify the release tag, (otherwise you will get the latest code in the master branch). import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.3.0/contracts/token/ERC20/ERC20.sol";
    – abcoathup
    Commented Sep 4, 2019 at 0:09
  • What if I want to import via GitHub, not using Remix? Commented Sep 4, 2019 at 9:18
  • I haven't used Python, so not sure how to do this.I use OpenZeppelin SDK and Truffle.
    – abcoathup
    Commented Sep 4, 2019 at 9:36

0

Your Answer

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