Solidity

Solidity Abstract Contracts

Solidity Abstract Contracts Main Tips

  • Some contracts cannot be compiled themselves because their functions lack implementation, but can be used as a base.
  • If a contract inherits from an abstract contract, it must implement all functions that lack implementation, else it becomes abstract itself.

Solidity Abstract Contracts

As shown in the code example below, certain contract functions may lack implementation. In this case, notice how the function declaration header gets terminated by a ; symbol:

Example

pragma solidity ^0.4.0;

contract Felinae {
    function utterance() returns (bytes32);
}

 

Try on Remix Try live on Hosting

Contracts like that are not compilable (even if there are implemented functions along those that are not), but they are usable as base contracts:

Example

pragma solidity ^0.4.0;

contract Felinae {
    function utterance() returns (bytes32);
}

contract Cheetah is Felinae {
    function utterance() returns (bytes32) { return "sneaky cat"; }
}

 

Try on Remix Try live on Hosting

If a contract inherits from an abstract contract, it must implement all functions that lack implementation, else it becomes abstract itself.

Read previous post:
Solidity Inheritance

Solidity Inheritance Main Tips Solidity supports multiple inheritance in the form of copying copying code, which includes polymorphism. When inheriting from...

Close