简体   繁体   English

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

[英]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.

相关问题 错误:返回错误:处理事务时 VM 异常:还原只有所有者可以调用此 function - Error: Returned error: VM Exception while processing transaction: revert only owner can call this function 松露错误:错误:处理事务时VM异常:恢复 - Truffle error: Error: VM Exception while processing transaction: revert 返回错误:VM Exception while processing transaction: revert only owner can call this function - Returned error: VM Exception while processing transaction: revert only owner can call this function 错误:返回错误:处理事务时出现 VM 异常:气体不足 - Error: Returned error: VM Exception while processing transaction: out of gas Solidity - Truffle:错误:处理事务时出现 VM 异常:无效的操作码不是因为恢复 - Solidity - Truffle: Error: VM Exception while processing transaction: invalid opcode NOT because of revert Openzepplin众包合同获得:处理事务时VM异常:恢复错误 - Openzepplin crowdsale contract got: VM Exception while processing transaction: revert error brownie:ValueError: execution reverted: VM Exception while processing transaction: revert - brownie:ValueError: execution reverted: VM Exception while processing transaction: revert 在松露控制台中使用OpenZeppelin ERC721 Mint时,“处理事务时发生VM异常:还原” - “VM Exception while processing transaction: revert” when using OpenZeppelin ERC721 mint in truffle console 处理事务时VM异常:缺少气体 - VM Exception while processing transaction: out of gas 处理事务时VM异常:PromiEvent上的操作码无效 - VM Exception while processing transaction: invalid opcode at PromiEvent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM