0

I'm trying to use Remix to interact with a suite of contracts. One of the contracts being used is OpenZeppelin's Ownable contract. I copied from the link above, and pasted it into Remix, with a few changes to take out the OpenGSN stuff, and also dropping the Solidity version (due to requirements elsewhere in the suite):

pragma solidity ^0.5.0;

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable {
    address private _owner;
    ....

This yields the following error:

ParserError: Expected pragma. import directive, or contract/library/interface definition
abstract contract Ownable {
^-------^

I've tried all kind of things. Via a comment here I've tried retyping the first line by hand, along with the first line of the contract code. I've tried taking out the abstract (update: I made a mistake with this, see the answers), I tried making up an import, removing the caret (^) from the Solidity version, and general monkeying around with the code to make it work. Nothing has gotten rid of this error.

There are a number of other questions with this precise error, though I have not been able to extrapolate from any of the ones I've seen why this error would be appearing here.

Why am I getting this error?

2

The abstract keyword has been introduced in the Solidity version 0.6.0.

Just update your contract from version 0.5.0 to 0.6.0 or, if you can't, change it to be compatible with the 0.5.0 release. This page about the breaking changes between the two releases could help you a lot : (https://docs.soliditylang.org/en/v0.6.0/060-breaking-changes.html).

Note that the pragma directive used by the 0penZeppelin Ownable contract is pragma solidity >=0.6.0 <0.8.0;. If you use a previous Solidity release you should expect some errors in your code.

4
  • You might notice in the question that I mentioned I needed to be using v5 for other contracts that inherit (unfortunately). I also mentioned that I had tried taking out abstract, though I double-checked after seeing your answer, and saw that I had been mistaken, and that the errors I was getting after removing abstract were different errors - they were due to two functions in the contract using virtual identifiers. So the basic gist of your answer is correct, thanks, but please edit the suggestion to update the version of Solidity to reflect the question. Thanks! – The Renaissance Dec 3 '20 at 10:24
  • I answered the question about Remix: ParserError: Expected pragma. import directive, or contract/library/interface definition which is caused by the abstract keyword with solidity 0.5.0. By removing it you have a new error with the virtual keyword which has been introduced too by Solidity 0.6.0. See the last sentence of my answer : if you use a 0.6.0 contract with 0.5.0 you will face plenty of errors.I advise you to learn the breaking changes between the two releases, then you should be able to update your contract accordingly. – clement Dec 3 '20 at 10:42
  • You can possibly open a new question to target a specific issue (for exemple about the virtual keyword and how to migrate a contract from 0.6.0 to 0.5.0). – clement Dec 3 '20 at 10:44
  • 1
    no need, it was just about taking virtual out of the two functions that used it as an identifier - thanks – The Renaissance Dec 3 '20 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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