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

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>