Remix Errors – Fixing ParserError: Expected pragma, Import Directive, or Contract Definition

errorremixsolcsoliditysolidity-0.5.x

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?

Best Answer

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.

Related Topic