[Ethereum] If i am writing two contracts A,B and extending one with other then can i use methods from contract A in contract B when i am deploying


If i am having two contracts extending one with other then can i use methods available in one contract in another when i have deployed.We have to take them in one file or have to deploy differently and getting them by addresses.

Best Answer

Inheritance is not an Ethereum feature but you can use it during the development phase to improve code maintenance. For example, you can use inheritance in Solidity. In any case, all parent contracts will be included in the compiled contract, so it will have all the code needed to run as a single contract.

Even if a contract inherits from multiple other contracts, only a single contract is created on the blockchain, the code from the base contracts is always copied into the final contract.

Moreover, Ethereum lets a contract to call code from another contract (i.e. Call function on another contract), but it has nothing in common with contract inheritance.

Related Topic