简体   繁体   中英

“VM Exception while processing transaction: revert” when using OpenZeppelin ERC721 mint in truffle console

I am using OpenZeppelin's ERC721 with the simple mint function. However, I get VM Exception while processing transaction: revert when I call the function in truffle console

I first open up Ganache, and then I migrate truffle migrate --reset . Then, I truffle console , then I set up the contract SimpleStorage.deployed().then((instance)=>{app=instance}) . Finally I call the function and get the error app.buyOneToken

Here is my SimpleStorage.sol

pragma solidity >=0.4.21 <0.6.0;

import './MyToken.sol';

contract SimpleStorage {

  //The ERC721 token
  MyToken public myToken;
  uint256 public tokenId;

  constructor (MyToken _myToken) public {
    myToken = _myToken;
    tokenId=0;
  }

  function buyOneToken() public payable {
    myToken.addMinter(msg.sender);
    require(myToken.mint(msg.sender, tokenId));
    tokenId++;
  }
}

Here is MyToken.sol

pragma solidity >=0.4.21 <0.6.0;

import 'openzeppelin-solidity/contracts/token/ERC721/ERC721Full.sol';
import 'openzeppelin-solidity/contracts/token/ERC721/ERC721Mintable.sol';

contract MyToken is ERC721Full, ERC721Mintable{

  string name;
  string symbol;

  constructor (string memory _name, string memory _symbol) public 
ERC721Full(_name, _symbol) {
     // solhint-disable-previous-line no-empty-blocks
     name=_name;
     symbol=_symbol;
  }
}

Here is the migration for both .sol files, 2_deploy_contracts.js

var SimpleStorage = artifacts.require("./SimpleStorage.sol");
var MyToken = artifacts.require("./MyToken.sol");

module.exports = function(deployer) {
  const _name = "Like Token";
  const _symbol = "LIKE";
  deployer.deploy(MyToken, _name, _symbol).then(function(){
    return deployer.deploy(SimpleStorage, MyToken.address);
  });
};

I have a modified version where I only migrate MyToken.sol (which has access to OpenZeppelin's ERC721 library). I can mint a token fine then. However, when I follow the procedure outlined above after migration and using the truffle console to call the function, I get the error.

ERC721Mintable.mint has an onlyMinter modifier.

Try adding a minter address and then calling mint from this address.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM