Hi @karendj,
Q3
Q1
This part of your answer is correct
But I wouldn’t call the parent/base contract the main contract, as I think that could be misleading. The main purpose of a parent/base contract is to be inherited, and therefore to “supply” the derived contract with other, often more specialised, supporting functionality. When a derived contract is compiled, the functionality it inherits from its parent(s) is incorporated into a single set of bytecode, which is then deployed as a single smart contract at a single Ethereum address on the Ethereum blockchain.
Also, it’s important to understand that a base contract is any parent contract that is inherited by a derived contract. Within an inheritance structure there can be more than one base contract e.g.
// Multi-level inheritance structure
contract A { ... }
contract B is A { ... }
contract C is B { ... }
In this multi-level inheritance structure:
C is a derived contract
A is a base contract… but not the only base contract …
B is both a derived contract (of A), and a base contract (to C)
Basically…
parent contract = base contract
child contract = derived contract
They are just alternative terms for the same thing.
Q2
No… not all of the functions in a parent contract are available for its derived contract(s). Functions with public
or internal
visibility are available, but not those with private
visibility.
A function in the parent contract with external
visibility will be inherited by a derived contract, but only to the extent that, when the derived contract is deployed, this function will be available to call externally e.g. from Remix, a web3 client (such as the front-end interface of a dapp), or from an external (i.e. non-derived) contract. However, unlike public
and internal
functions, an external
function in the parent contract is not available to be called from within the derived contract itself.
The only functions which aren’t inherited are those with private
visibility.
Let me know if anything is unclear, or if you have any questions