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.


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.


Inheritance in Solidity works as in many oop languages, meaning that of course you can call a parent function, see Solidity in the wiki.

Also both contracts can be in same file or separated files as long as they are created altogether in order for name based inheritance to work.

Note that both contracts will have separated addresses so you can also call a function of either parent or child contract using its address.

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.