Inheritance Reading Assignment

  1. The base contract is the contract inherited from
  2. All public and internal functions of the base contract
  3. Where multiple contracts inherit from the same base contract.
1 Like
  1. What is the base contract?
    Parent contract where child inherited from
  2. Which functions are available for derived contracts?
    All public and internal functions
  3. What is hierarchical inheritance?
    Multiple contracts inherit from the same base
1 Like
  1. A base contract is also known as the parent contract. A base contract will pass all of its functions, variable, data, etc to the derived or children contracts.

  2. Functions in the parent contract that have the visibility modifiers of public and external are available for derived contracts.

  3. Hierarchical inheritance is a situation in which there is a single base contract that acts as a parent for multiple derived contracts. An example of this would be a parent contract A. All of the derived contracts of that parent would be for example: B is a child of A, C is a child of A, D is a child of A, etc.

1 Like
  1. A base contract (or parent contract) is the contract whose code can be used by a derived (child) contract

  2. Public and internal functions are available for derived contracts

  3. Hierarchical inheritance is where a single contract is a base contract for multiple derived (child) contracts.

1 Like

Hi @dcota,

Q1 & Q3 :ok_hand:

That’s correct, but what types of visibility prevent (more than just restrict) functions and state variables being inherited?

Hi Paul,

Q1 & Q3 :ok_hand:

Correct

but not all of them — (see the answer to Q2)

Public and internal (not external) functions are available for derived contracts. Those with private or external visibility are not inherited. The same is true for state variables and mappings (although these can’t have external visibility anyway).

Ah ok. So the base contract will pass its functions, variables, data, etc to the children if the variables, functions, etc are set to public or internal.

If they are set to private then they will only be available within the contract they are located. And if they are set to external they will not be inherited in the children contracts. The external modifiers can be accessed from outside of the contract but will not be passed down to the children contracts if any are created.

Does this sound a bit more correct?

1 Like
  1. What is the base contract?
    Base is a parent contract, that is inherited
  2. Which functions are available for derived contracts?
    Derived or child contracts have available all public and internal scoped functions and state variables
  3. What is hierarchical inheritance?
    When a single contract acts as a base contract for multiple derived contracts
1 Like

Yes, for functions and state variables (not any local variables defined within functions). The state variables are the ones we declare outside of the functions, usually somewhere at the top of the contract.
All modifiers and events are inherited by derived contracts (which makes sense if you think about it, because we don’t state any visibility for these).

Correct.

Yes, you’ve got it :muscle: :smiley:
external visibility in fact only applies to functions. State variables cannot be marked external and external modifiers and events also don’t exist (as I mentioned above modifiers and events are available within the same contract and to its children); so events and modifiers are both effectively internal, although we don’t state that.

What is the base contract?
When we have contracts in a parent-child relationship, the parent contract is also known as base contract.

Which functions are available for derived contracts?
All public and internal scoped functions from the base contract…

What is hierarchical inheritance?
When we have one contract that is a base contract for multiple derived contracts.

1 Like

What is the base contract?
Answer: The parent contract.

Which functions are available for derived contracts?
Answer: All public and internal functions and state variables are available for derived contracts.

What is hierarchical inheritance?
Answer: Inheritance is the process of defining multiple contracts that are related to each other through parent-child relationships. The contract that is inherited is called the parent contract and the contract that inherits is called the child contract.

1 Like
  1. The base contract, also known as the parent is the where all child contracts inherit from.
  2. All public and internal functions
  3. It’s where you have a single parent contract where multiple child contracts derive from.
1 Like

What is the base contract?
This is the contract that is used by other contracts to be derived from. E.g. A is B -> A is the base conract.

Which functions are available for derived contracts?

  • public
  • internal

What is hierarchical inheritance?
This occurs when multiple child contracts are derrived from the same base contract. Eg:

  • Vehicle
  • Car is Vehicle
  • Truck is Vehicle
1 Like
  1. The contract that is inherited is called the parent contract aka base contract.
  2. All public and internal scoped functions and state variables are available to derived contracts.
  3. In a hierarchical inheritance a single contract acts as a base contract for multiple derived contracts.
1 Like
  1. A base contract is a parent contract that has state variables and functions.A base contract can be derived in to child contracts where its state variables and functions are available.
  2. The derived contract state variables and functions plus the parent contract state variables and functions.
  3. Hierarchical inheritance is where multiple contracts are derived from same base contract.
1 Like

What is the base contract?
Parent contract.

Which functions are available for derived contracts?
All of the public and internal functions are available for derived contracts.

What is hierarchical inheritance?
It is similar to single contract , hierarchical inheritance is when a parent contact act as base contract for multiple childs

1 Like
  1. What is the base contract
    It is the parent contract when using inheritance.

  2. Functions available to derived contracts are the public and internal functions.

  3. hierarchical inheritance is where a contract can be inherited by more than one contract. Following the example of a tree diagram.

1 Like
  1. What is the base contract?
    It’s a contract that is the parent of a child contract. A child contracts inherits from the base contract.

  2. Which functions are available for derived contracts?
    Internal and public functions are available.

  3. What is hierarchical inheritance?
    Basically, it is a situaiton where multiple contracts inherit from a common parent.

1 Like

Redoing this part in the updated course. Maybe it would be easier to understand some of the inheritance stuff with realworld examples. The thing that has been bogging my mind lately is that a lot of projects in defi have separate deployer contracts. These contracts can not be read or interacted with. How are deployer contracts used? They must be interacted with right, is the contract code only shown on etherscan if it has been made ā€œopen sourceā€?

One example is falconswap, trying to figure out more about the project and there are some red flags. Is there anyway to get to understand the time lock on supposedly a contract with liquidity for the release of falconswap on mainnet. The deployer contract is here: 0xb162046627dd7251171bD6C3D4E5c473D4507dD9

Many thanks! Solidity is like a rabbithole, the more you think you start to understand, the more you understand that you dont :slight_smile:

  1. What is the base contract?

The base contract is the parent contract.

  1. Which functions are available for derived contracts?

All public and internal scoped functions

  1. What is hierarchical inheritance?

Hierarchical inheritance is where a single base contract exists from which multiple child contracts are derived.

1 Like