Learn how to use inheritance to bring functionality from one contract into another.
Inheritance.sol
and add two simple contracts, each with a function identifying which contract called it:
ContractA
says that it is “contract A” and ContractB
says that it is “contract B”.
is
keyword in the contract declaration. Update ContractA
so that it is
ContractB
, and delete the whoAmI
function from ContractA
.
Reveal code
ContractA
doesn’t have any functions in it, the deployment still shows the button to call whoAmI
. Call it. ContractA
now reports that it is “contract B”, due to the inheritance of the function from Contract B
.
internal
functions from contracts they inherit from. Add an internal
function to ContractB
called whoAmIInternal
that returns “contract B”.
Add an external function called whoAmIExternal
that returns the results of a call to whoAmIInternal
.
Reveal code
ContractB
, the whoAmIInternal
function is not available, as it is internal
. However, calling whoAmIExternal
can call the internal
function and return the expected result of “contract B”.
private
function from a contract that inherits from the contract containing that function.
artifacts
folder.
Any empty contract:
internal
functions, but they cannot call private
functions. You’ve also learned that inheriting from a contract adds the size of that contract’s bytecode to the total deployed size.