關于solidity開發(fā)時遇到的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;
}
}
發(fā)現(xiàn)在運行構造函數(shù)處提示VM Exception while processing transaction: invalid opcode錯誤。
改正方法如下:文章來源:http://www.zghlxwxcb.cn/news/detail-620631.html
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;
}
}
然后將修改后編譯成功,運行不再報錯。在改回原來的節(jié)點環(huán)境也能運行了。
文章來源地址http://www.zghlxwxcb.cn/news/detail-620631.html
到了這里,關于solidity報錯處理:VM Exception while processing transaction: invalid opcode的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!