javascript - 如何在 web3.js 上打印 solidity revert me 消息?
问题描述
我正在尝试编写一个拍卖平台。当合约发送一个还原函数时,我想在屏幕上显示它。我正在使用 web3.js 1.5 版。
这是相关的solidity代码;
function bid() public payable {
require(
now <= auctionEndTime,
"Auction already ended."
);
require(
//I want to print this error on screen.
msg.value > highestBid,
"There already is a higher bid."
);
if (highestBid != 0) {
pendingReturns[highestBidder] += highestBid;
}
highestBidder = msg.sender;
highestBid = msg.value;
emit HighestBidIncreased(msg.sender, msg.value);
}
这是出价和获取错误的 javascript 代码;
async bid(amount) {
if(this.state.auction!=='undefined'){
try{
await this.state.auction.methods.bid().send({value: this.state.web3.utils.toWei(amount).toString(), from: this.state.account})
} catch (e) {
console.log(e)
}
}
}
如果我出价低于最高出价,这就是我在控制台上得到的;
{代码:-32603,消息:
Error: [ethjs-query] while formatting outputs from…/task_queues.js:93:5)","name":"RuntimeError"}}}}'
,堆栈:Error: Error: [ethjs-query] while formatting outpu…/task_queues.js:93:5)","name":"RuntimeError"}}}}'
}
我想要的是打印“已经有更高的出价”。在控制台上,但我无法让它工作。我阅读了 web3 文档和元掩码文档,但没有运气。谢谢您的回答。
解决方案
推荐阅读
- javascript - Nativescript 中的 GridLayout 和 StackLayout UI 设计
- ffmpeg - 通过 ffplay 播放 USB 网络摄像头流时出现“无法解码 APP 字段”
- c - computet 是否将每个 ascii 数字(二进制)转换为其等效的数字(二进制)?
- php - 无法验证未注册的 3d 安全卡(安全交易)
- c# - 测试多个标志值
- python - Python 循环加法
- powershell - power shell not null check in if statement
- ruby - Ruby 当前类实际上是什么?
- php - 如果 Woocommerce 中的产品缺货,则用表单替换数量字段
- java - java.lang.NoClassDefFoundError: com.ibm.mq.MQQueueManager(初始化失败)