If MyCo.sol contract needs to access the Owned.sol contract, how is the file firing? Does the Owned.sol file have to be added to the blockchain prior to firing MyCo.sol; if so, does it just need to be set under the owners contract/address prior to executing ?
Does the ./ or ../ location reference some location on the chain or only used to locate the file prior to setting it with a tx?


import "../lib/Owned.sol"; 

how does MyCo.sol know where to find the imported files? Have they become embedded somehow in the initial migration?
I think I am just confused about the blockchain file structure and how it would access these imported files. Is it all resident on the chain, or a hybrid between the MyCo.sol, the native go-ethereum language, and wbd3.js protocols?

1 Answer 1


It's a compiler directive that tells it to load the file from the compile-time local file system. It's not relevant to anyone who uses the compiled contract other than verifying the bytecode against source; they will need to see it.

Although there are emerging de facto standards for such things, there is no assurance that your particular Owned.sol exactly matches anyone else's. Consequently, the actual source you are using for Owned.sol is part of your project and should be published with the rest of your code in the case that you want to publicize your source code.

import is roughly equal to including in the same source file, with the obvious advantage of avoiding code duplication:

contract Owned {
  // do something

contract Mine is Owned {
  // do something

Hope it helps.

  • That helped a lot, thank you. If I wanted not to duplicate code in my contract, could i point the import command to a contract hash instead of a defacto standard? for example: The import would be: import "../txid" , or could I point it to a myname.eth resolved name and point it to a contract on the chain; which in turn would call the contract from the chain and import it to mMyCo.sol? or is my thinking skewed?
    – finneyman
    Commented Jul 13, 2017 at 18:40
  • You can only point at source you have, not a deployed contract. But, Solidity has a different facility called Libraries that refer to published contracts you can use to avoid repetition. Commented Jul 13, 2017 at 22:33

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.