15

I failed to compile a solidity file with import statement.

Error: Source not found: File not found. import './contract.sol';

How should we set a import path?

I used web3.js for compiling.

web3.eth.compile.solidity(data);

Layout of a Solidity Source File — Solidity 0.2.0 documentation http://solidity.readthedocs.org/en/latest/layout-of-source-files.html

Satoshi Nakanishi
  • 5,749
  • 7
  • 38
  • 57

1 Answers1

11

Files and paths are explained in detail here: http://solidity.readthedocs.org/en/latest/layout-of-source-files.html

Key points:

Paths

In import "filename";, filename is always treated as a path with / as directory separator, . as the current and .. as the parent directory. Path names that do not start with . are treated as absolute paths.

To import a file x from the same directory as the current file, use import ”./x” as x;.

Use in actual Compilers

When the compiler is invoked, it is not only possible to specify how to discover the first element of a path, but it is possible to specify path prefix remappings so that e.g. github.com/ethereum/dapp-bin/library is remapped to /usr/local/dapp-bin/library and the compiler will read the files from there. If remapping keys are prefixes of each other, the longest is tried first. This allows for a “fallback-remapping” with e.g. “” maps to “/usr/local/include/solidity”.

tayvano
  • 15,961
  • 4
  • 45
  • 74