0

I am following the CryptoZombies tutorial to create an Oracle Interface. However, I am having an error in Smart Contract which will be my interface, according to the tutorial it is the same, 2 details that are different is the "pragma" version, in CryptoZombie they are using version 0.5.0, however I am all versions from 0.4 on, the second detail is the name of the function that I have customized for my case.

My code:

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

contract GhilOracleInterface {
  function getAmountAvailable() public returns (uint256);
}

Output:

TypeError: Contract "GhilOracleInterface" should be marked as abstract.
 --> project:/contracts/GhilOracleInterface.sol:4:1:
  |
4 | contract GhilOracleInterface {
  | ^ (Relevant source part starts here and spans across multiple lines).
Note: Missing implementation:
 --> project:/contracts/GhilOracleInterface.sol:5:3:
  |
5 |   function getAmountAvailable() public returns (uint256);
  |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

,TypeError: Functions without implementation must be marked virtual.
 --> project:/contracts/GhilOracleInterface.sol:5:3:
  |
5 |   function getAmountAvailable() public returns (uint256);
  |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 Answer 1

0

Your code is valid for solidity < 0.6.0 but not above as you can see here.

The new keyword abstract can be used to mark contracts as abstract. It has to be used if a contract does not implement all its functions.

Functions without implementation outside an interface have to be marked virtual.

You are using a compiler with a version > 0.6.0, this is why you get the errors.

So you either adopt the new abstract / virtual keywords and use pragma > 0.6.0. Or keep your current code and specify a pragma < 0.6.0.

// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;

abstract contract GhilOracleInterface {
  function getAmountAvailable() public virtual returns (uint256);
}

If you are doing a tutorial, maybe it's best that you specify a pragma compatible with the code you are being provided.

such as :

pragma solidity >=0.4.22 <0.6.0;

You will also need to use a compiler that fits this version range.

On Remix, you can do this easily in the Solidity Compiler tab :

enter image description here

If you are using truffle you can edit your configuration file to select the last 0.5.x version:

compilers: {
    solc: {
      version: "^0.5",
    },
  },
2
  • Thanks for the answer, and to use with newer versions what would my code look like then? Do you have an example?
    – Crazy
    Oct 28, 2021 at 12:46
  • I edited my answer with the exemple.
    – hroussille
    Oct 28, 2021 at 13:03

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.