I am new to Ethereum and I was wondering if it is possible to deploy a smart contract such that other smart contracts are not able to inherit from it. In other words once a smart contract is deployed can other smart contracts inherit from it?
2 Answers
Smart contracts don't inherit from deployed smart contracts. Inheritance is a feature of the Solidity language, Solidity is compiled to EVM bytecode which is what is stored/deployed on the Ethereum blockchain.
When you inherit a contract in Solidity, the inherited contracts functionality is copied into the inheriting contract during the compilation process. The compiled bytecode is what is deployed to the Ethereum blockchain.
-
I am just thinking how it would be great if this is possible. We import thousands of not millions of open zeppelin Erc20 and Erc721 smart contracts that are the same bytecode. What if we could deploy them once and then just inherit them as import them and extend them. That somehow compiler just copies bytecode that is already on blockchain and adds only new one that extrends it.– BlissfulCommented Sep 5, 2022 at 9:32
As per my understanding also what @willjgriff says is correct. i.e. When Inheriting they do not use other deployed contract but have that code in the same address.
However if you want a child contract not to use any member in the parent contract, you can make them private
, so the child contract may need some other member of the parent class to access that private member (may be some validating function).