Abstract Contracts

Abstract contracts in Solidity serve as basic blueprints, specifying the structure and a set of functions that derived contracts must implement. They can’t be instantiated and serve mostly as a template for other contracts to follow. Any derived contract that derives from an abstract contract must implement the incomplete functions, or else it will be labeled as abstract. It specifies the structure of the contract, and any derived contract that inherits from it must do the same.

Characteristics of abstract contracts

Here are the key characteristics of abstract contracts:

  • No implementation: These contracts contain at least one function without implementation. These functions act as placeholders, indicating that their details must be provided by any contract inheriting from the abstract contract.

  • Incomplete constructors: Contracts with incomplete constructors or lacking parameter supply to basic constructors can also be considered abstract. An abstract contract typically doesn’t have a fully implemented constructor.

  • Foundation for inheritance: These contracts are designed to be inherited by other contracts. They set the structure and define a contract template. Derived contracts build upon this template by providing concrete implementations for abstract functions.

  • No instantiation: Instances of abstract contracts can’t be created. They serve as a foundation for other contracts and are meant to be extended and implemented.

Declaration of abstract contracts

The abstract keyword is used to declare an abstract contract. This signifies to the compiler that the contract is incomplete and serves as a base for other contracts to fill in the missing details.

Get hands-on with 1200+ tech skills courses.