在松露控制台中使用OpenZeppelin ERC721薄荷时"VM Exception while processing transaction: revert"



我正在使用OpenZeppelin的ERC721和简单的mint函数。然而,当我调用truffle console中的函数时,我得到了VM Exception while processing transaction: revert

我首先打开Ganache,然后迁移truffle migrate --reset。然后,我truffle console,然后我建立了合同SimpleStorage.deployed().then((instance)=>{app=instance})。最后,我调用函数并得到错误app.buyOneToken

这是我的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++;
}
}

这是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;
}
}

以下是两个.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);
});
};

我有一个修改过的版本,我只迁移MyToken.sol(它可以访问OpenZeppelin的ERC721库)。那我就可以象征性地罚款了。然而,当我在迁移后按照上面概述的过程并使用truffle控制台调用函数时,我会收到错误。

ERC721Mintable.mint有一个onlyMinter修饰符。

请尝试添加minter地址,然后从此地址调用mint。

相关内容

最新更新