I am using Truffle together with Ganache and I can't get this code to run:

pragma solidity >=0.4.21<0.6.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract UniqueAsset is ERC721{

using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
mapping(string => uint8) hashes;

  constructor() public ERC721("UniqueAsset", "UNA") {}

function awardItem(address recipient, string memory hash, string memory metadata)
  returns (uint256)
    require(hashes[hash] != 1);

    hashes[hash] = 1;
    uint256 newItemId = _tokenIds.current();
    _mint(recipient, newItemId);
    _setTokenURI(newItemId, metadata);
    return newItemId;

it shows me the following error:

:15:1: ParserError: Expected pragma, import directive or contract/interface/library definition.
function awardItem(address recipient, string memory hash, string memory metadata)

Anybody an idea whats wrong?

  • 1
    Remove the bracket line 13 after the constructor and add it at the end of the file.
    – clement
    Apr 3 at 16:04

There are a number of things you need to change:

  • Your pragma statement needs a space in it between the versions. Change it to pragma solidity >=0.4.21 <0.6.0;
  • The OpenZeppelin contracts you are importing require Solidity 0.8.0 or greater. You will need to change your pragma statement to reflect this
  • You have a closing bracket on line 13 after the constructor. That should not be there -- move it to the end of the file.
  • _setTokenURI() is not a function on the contract you are importing. See more here.
  • 1
    Hi Shane, thank you for your answer unfortunately I'm not a full stack developer yet, so i don't understand a lot from the link you've sent :-| can you help me with which function should i use instead? thank again
    – Tal Dotan
    Apr 3 at 16:23
  • I am not sure. I think it would be a good exercise to figure that out, as the learnings you will gain by figuring that out should help design the rest of the contract! Apr 3 at 16:50

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.