1

If one imports another contract and instantiates it with 'new', then I assume the binary of that imported contract must be fully included in my contract (increasing its deployment size accordingly).

If I instantiate the imported contract using an already deployed address however, does that also include that binary data into my contract when I deploy it?

How about if I don't instantiate it at all, but only use a enum or struct definition from that contract. Will the entire binary of the imported contract be added to my contract's binary?

0

If one imports another contract and instantiates it with 'new', then I assume the binary of that imported contract must be fully included in my contract (increasing its deployment size accordingly).

That's correct

If I instantiate the imported contract using an already deployed address however, does that also include that binary data into my contract when I deploy it?

No, it doesn't. Solidity will only use the imported contract's function signatures that are used by the calling contract.

How about if I don't instantiate it at all, but only use a enum or struct definition from that contract. Will the entire binary of the imported contract be added to my contract's binary?

No. Solidity's linker will only add actual used code to the final contract bytecode.

  • "And how would you do that?", maybe I didn't express myself clearly. I meant, instead of doing ImportedContract c = new ImportedContract(); what if ImportedContract has already been deployed and I'll do ImportedContract c = ImportedContract(contractAddress); - will this also append the entire ImportedContract binary to my contract? – user1282931 Aug 23 '18 at 11:33
  • Might have sounded a bit harsh there. As for your calrification: this does not create a new contract. This line just tells that Solidity that the contract at contractAddress can be treated as an ImportedContract, and it's reference is to be stored in c. – Henk Aug 23 '18 at 11:45
  • Yes exactly, my question is whether in this case the binary of ImportedContract will nevertheless be appended to my contract when I deploy it. – user1282931 Aug 23 '18 at 11:51
  • No, it won't, as that binary is part of another contract. – Henk Aug 23 '18 at 12:01

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.