繁体   English   中英

错误:返回错误:处理事务时出现 VM 异常:使用 New 创建时恢复

[英]Error: Returned error: VM Exception while processing transaction: revert when creating with New

我正在使用 Drizzle,每当我在此合同上调用createInvestorToken时,我都会收到Error: Returned error: VM Exception while processing transaction: revert 不知道如何调试这个。 它在测试中成功,但在其他情况下不会成功。

如果我删除allTokens.push(new InvestmentToken(_name,_symbol,initalSupply,_cost)); 有用。

// 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;
    }

}

在这种情况下,令牌达到了气体限制,并且错误没有显示为气体问题。

我认为因为它正在创建一个令牌,所以错误被抑制了。

暂无
暂无

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

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