VM Exception while processing transaction: invalid opcode

关于solidity开发时遇到的VM Exception while processing transaction: invalid opcode问题,我的代码如下:

pragma solidity ^0.4.16;
contract modifierTest{
    
    
    uint a=0;
    address owner;
    constructor() public{
    
    
        owner = msg.sender;
    }
     modifier onlyOwner{
    
    
        require(msg.sender == owner);
        _;
    }
    function changeIt(uint _a)public onlyOwner{
    
    
        a = _a;
    }
}

发现在运行构造函数处提示VM Exception while processing transaction: invalid opcode错误。

改正方法如下:

pragma solidity ^0.4.24;//改成了24版本,同时也要改编译器的版本
contract modifierTest{
    uint a=0;
    address owner;
    constructor() public{
        owner = msg.sender;
    }
     modifier onlyOwner{
        require(msg.sender == owner);
        _;
    }
    function changeIt(uint _a)public onlyOwner{
        a = _a;
    }
}

然后将
两点修改修改后编译成功,运行不再报错。在改回原来的节点环境也能运行了。节点

猜你喜欢

转载自blog.csdn.net/ing_An/article/details/122372862
今日推荐