• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

209
Views
How to print solidity revert me message on web3.js?

I'm trying to code an auction platform. When contract sends a revert function, I want to show it on screen. I'm using web3.js version 1.5.

This is the related solidity code;

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

This is the javascript code to bid & get error;

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

This is what I get on the console if I bid lower than highest bid;

{code: -32603, message: Error: [ethjs-query] while formatting outputs from…/task_queues.js:93:5)","name":"RuntimeError"}}}}', stack: Error: Error: [ethjs-query] while formatting outpu…/task_queues.js:93:5)","name":"RuntimeError"}}}}'}

What I want is to print "There already is a higher bid." on the console, but I couldn't make it work. I read web3 docs & metamask docs but no luck in there. Thank you for your answers.

almost 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error