1

I've noticed many times that most of the contract do not import directly from Open zeppelin (for example IERC20 Interface, Ownable Interface, Safemath library and so on) but rather the full code is imported inside the smart contract.

An example?

Look at the Shiba Inu Smart Contract: https://etherscan.io/address/0x95ad61b0a150d79219dcf64e1e6cc01f0b64c4ce#code

Inside the contract the IERC20 interface and Safemath library are copied rather then included from Open Zeppelin as an import statement.

Is there an advantage of doing so? Contract size advantage?

Thanks

1 Answer 1

2

No, there's no advantage, it's just a matter of preference.

Remember that ultimately all Solidity code gets compiled down to bytecode, and that bytecode reflects the actual stack functionality of the code. For that reason, whether or not different contracts are stored in different files before compilation is irrelevant to the bytecode size.

Another factor to consider, is that when developers submit their Solidity code to Etherscan it might be easier for them to just copypaste all file code into one file and submit rather than laboriously pasting all the files separately. This is what I think is happening in the Shiba Inu Etherscan contract, because they include multiple pragma statements, which – although you can do that without compilation errors – seems abnormal enough to call into question whether these contracts were all written in this form in the first place.

1
  • Everything you said makes sense for me. Thanks for sharing your point of view.
    – xcsob
    Nov 20, 2021 at 16:52

Your Answer

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

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