如何从UI中的合同修改器获取错误消息?

时间:2018-09-11 23:23:45

标签: ethereum solidity web3

在Remix上测试合约时,我注意到某个方法是否未通过修饰符,您实际上会在合约代码下方的窗口中看到错误消息。这是我可以从web3上获得的东西,还是我可以在自己的UI中从合同中获得此错误消息(如果提供)?

这是一个简单的合同:

address public owner;

modifier onlyOwner() {
    require(msg.sender == owner, "Owner account is required");
    _;
}

constructor() public {
    owner = msg.sender;
}

function doStuff()
external
view
onlyOwner
returns (bool) {
    return true;
}

当我不是通过混音从owner调用合同时,在控制台中会收到以下消息: call to Contract.doStuff errored: VM error: revert. revert The transaction has been reverted to the initial state. Reason provided by the contract: "Owner account is required". Debug the transaction to get more information.

该错误是否提供了可以从Web3事务中获得的东西?我看不到

0 个答案:

没有答案