I found the following case below in a book.

case 1:

contract sample1{
    function a() returns (int b);

contract sample2{
    function myFunc()
        sample1 s = sample1(0xd5f9d8d94886e70b06e474c3fb14fd43e2f23970);

        //without abstract contract this wouldn't have compiled

why use "0xd5f9d8d94886e70b06e474c3fb14fd43e2f23970"?

I found the following second case in the Solidity docs.

case 2:

contract Feline {
    function utterance() returns (bytes32);

contract Cat is Feline {
    function utterance() returns (bytes32) { return "miaow"; }

Feline is an abstract contract, and cat inherits from Feline.

What is the difference in case 1 and case 2?

Do you need to inherit to be able to use an abstract contract?


2 Answers 2


When using an abstract contract the functions declared in those abstract contracts must always be defined somewhere before they can be used. They can can be defined in 2 places:

  1. In another contract already deployed somewhere on the blockchain (which means it will have its own address 0xblahblahblah) and you will need to use that address to instantiate a reference to where those functions are defined in full. This is what the first block in your examples describes

  2. In the contract you are writing now and about to deploy but hasn't been compiled or deployed yet. If you do not provide the address to a contract which defines the functions listed in the abstract contract then YOU must define it in your new contract that references or inherits the abstract contract but the trick is that you have to use the exact function signature as used in the abstract contract to start your function definition. This is what your second example shows.


I know this is very old question, but as newer I also faced this problem.

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.6.0 <0.7.0;

abstract contract Feline {
    function utterance() public virtual returns (bytes32);

according to doc this is way of declaring abstract function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.