简体   繁体   English

在松露控制台中使用OpenZeppelin ERC721 Mint时,“处理事务时发生VM异常:还原”

[英]“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. 我正在使用带有简单薄荷函数的OpenZeppelin的ERC721。 However, I get VM Exception while processing transaction: revert when I call the function in truffle console 但是, VM Exception while processing transaction: revert时出现VM Exception while processing transaction: reverttruffle console调用函数时VM Exception while processing transaction: revert

I first open up Ganache, and then I migrate truffle migrate --reset . 我先打开Ganache,然后再迁移truffle migrate --reset Then, I truffle console , then I set up the contract SimpleStorage.deployed().then((instance)=>{app=instance}) . 然后,我truffle console ,然后设置合同SimpleStorage.deployed().then((instance)=>{app=instance}) Finally I call the function and get the error app.buyOneToken 最后,我调用该函数并得到错误app.buyOneToken

Here is my SimpleStorage.sol 这是我的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 这是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 这是两个.sol文件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). 我有一个修改后的版本,其中仅迁移MyToken.sol (可以访问OpenZeppelin的ERC721库)。 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. ERC721Mintable.mint具有onlyMinter修饰符。

Try adding a minter address and then calling mint from this address. 尝试添加一个铸造者地址,然后从该地址调用铸造者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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