Revert error in ERC721PresetMinterPauserAutoId

Hello there,

Thank you in advance for helping me, I'm getting a revert error in mintLand function which isn't the case because according to docs the contract deployer will be granted [DEFAULT_ADMIN/MINTER/PAUSER] roles.

I tried setting up the roles in the constructor, even though it didn't make sense to me but I'm still getting the same error. Would you kindly advise with what I'm missing/misunderstand here?

Here is a hypothetical scenario of my code:

// SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.6;

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

contract MarsToken is ERC721PresetMinterPauserAutoId {

    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;
    
    
    address public owner = msg.sender;

    
    struct Land{
        string landURI;
        uint256 initialPrice;
    }
    
    mapping(uint256 => Land) public landbyTokenId;
 

    constructor() ERC721PresetMinterPauserAutoId("MarsToken", "MARS", "https://mars.nasa.gov/") {}

    
    modifier landRegistered(uint tokenId) {
        require(_exists(tokenId), "MarsAuction: Land isn't registered!");
        _;
    }
    
    function mintLand(string memory _landURI, uint256 price) public returns(uint) {
        require(hasRole("MINTER_ROLE", msg.sender), "MarsToken: Not Authorized to mint");
        _tokenIds.increment();
        uint tokenId = _tokenIds.current();
        _mint(owner, tokenId);
        landbyTokenId[tokenId] = Land(_landURI, price);
        return tokenId;
    }

:computer: Environment

truffle / Remix

Hi, i can help you with that, contact me on telegram @OCPRobocop

Hi, welcome! :wave:

It seems like you set a wrong parameter for hasRole(), you can have a look at the AccessControl.sol

function hasRole(bytes32 role, address account) public view override returns (bool) {
    return _roles[role].members[account];
}

so you should pass a parameter of type bytes32, I think you can change your code as following:

require(hasRole(keccak256"MINTER_ROLE", msg.sender), "MarsToken: Not Authorized to mint");