DEV Community

Cover image for Smart Contract Inheritance.

Posted on

Smart Contract Inheritance.

Inheritance Overview
As with many object-oriented languages, Solidity includes inheritance as a feature.

Inheritance means that you can create an object with some values/methods and use it as a base for other objects.
In Solidity, the objects we're referring to are contracts and interfaces. We can write a contract with state variables and functions. Then we can create contracts that inherit those variables and functions. These derived contracts can then choose to add behavior as necessary.

Smart contracts can inherit other contract by using the is keyword. More specifically, a contract that inherits is the child and the inheritor is the parent. Using the is keyword in Solidity establishes a smart contract parent-to-child chain. So whenever you think of inheritance, just think of the father-son relations.

Image description

Inheritance allows programmers to create classes that are built upon existing classes, to specify a new implementation while maintaining the same behaviors.

Contracts can inherit other contracts by using the is keyword.

Just as illustrated in the diagram above, the syntax to establish inheritance between smart contracts in Solidity is to simply us the is keyword in the child contract - which creates an explicit pointer to the parent contract:

contract A {


contract B is A {


In this case Contract A is the parent contract, often times referred to as the base contract whereas Contract B is the child contract, often referred to as the derived contract. Let's break down the different types of smart contract inheritance in Solidity.

Top comments (0)