[英]Error: Returned error: VM Exception while processing transaction: revert when creating with New
I'm using Drizzle and when ever I call createInvestorToken on this contract I get Error: Returned error: VM Exception while processing transaction: revert .我正在使用 Drizzle,每当我在此合同上调用createInvestorToken时,我都会收到Error: Returned error: VM Exception while processing transaction: revert 。 Not sure how to debug this.
不知道如何调试这个。 It succeeds in the test, but it won't succeed otherwise.
它在测试中成功,但在其他情况下不会成功。
If I remove the allTokens.push(new InvestmentToken(_name,_symbol,initalSupply,_cost));如果我删除allTokens.push(new InvestmentToken(_name,_symbol,initalSupply,_cost)); it works.
有用。
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.21 <0.7.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract InvestmentToken is ERC20{
string public name;
string public symbol;
uint256 public decimals = 0;
uint256 public INITIAL_SUPPLY;
uint256 public cost;
address public parent;
constructor(string memory _name, string memory _symbol, uint256 initalSupply, uint256 _cost) public {
name = _name;
symbol = _symbol;
INITIAL_SUPPLY = initalSupply;
cost=_cost;
parent = msg.sender;
_mint(msg.sender, INITIAL_SUPPLY);
}
function buyToken(address receiver, uint256 amount) public {
if (msg.sender != parent) {
revert("You may only buy through the DPAC token");
}
uint256 tokensLeft = balanceOf(msg.sender);
if (tokensLeft >= amount/cost){
_transfer(msg.sender,receiver, amount/cost);
} else {
revert("There are no more tokens");
}
}
}
contract TheParentToken {
string public name = "DPAC_Token";
string public symbol = "DPAC";
uint256 public decimals = 0;
uint256 public INITIAL_SUPPLY = 10000;
uint256 public numberOfTokens = 0;
mapping(address => bool) public tokenWhiteList;
InvestmentToken[] public allTokens;
address public administrator;
constructor() public {
administrator = msg.sender;
allTokens.push(new InvestmentToken("A","B",1000,1));
allTokens.push(new InvestmentToken("B","C",1000,1));
numberOfTokens = allTokens.length;
}
function createInvestorToken(string memory _name, string memory _symbol, uint256 initalSupply, uint256 _cost) public {
allTokens.push(new InvestmentToken(_name,_symbol,initalSupply,_cost));
numberOfTokens = allTokens.length;
}
function addTokenToWhiteList(address newToken) public {
if(msg.sender != administrator){
revert("Not Admin");
}
tokenWhiteList[newToken]=true;
}
function removeTokenFromWhiteList(address newToken) public {
if(msg.sender != administrator){
revert("Not Admin");
}
tokenWhiteList[newToken]=false;
}
}
In this case the token was hitting the gas limit, and the error wasn't being displayed as the Gas Issue.在这种情况下,令牌达到了气体限制,并且错误没有显示为气体问题。
I think because it was creating a token the error is suppressed.我认为因为它正在创建一个令牌,所以错误被抑制了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.