0

I am using web3 over the Rinkeby test network for my solidity project. I am trying to get the exact revert message, using the error object.

try{
await contract.methods.acceptBattle(id).send({
from: address,
value:val
});
return '';
}
catch(e){
console.log(e.message);
}

After the code is running in the catch block, I am getting the output in the following format:

execution reverted: This battle isn't exist. 0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001b426174746c65206e7 56d6265722069736e27742065786973742e0a0000000000

Is there a way to get only the message itself (in the first row) and not the address coming after? As I saw in Do all Ethereum networks return the revert reasons as a “message” field?

and since I am running over the Rinkeby test network, the address supposed to be part of the data field of the error and not part of the message.

This is the relevant code for the revert message:

function acceptBattle(uint256 battle_id) public payable{
    Battle storage bate=battleInfo[battle_id];
    require(bate.amountBet>0, "Battle number isn't exist.\n");
    require(bate.creator!=msg.sender, "Impossible to fight against yourself.");
    require(bate.creator==bate.opponent, "This battle is closed, opponent already exist.");
    require(msg.value==bate.amountBet, "Betting value isn't as specified for this battle.");
    bate.opponent=msg.sender;
}
TylerH
  • 20,799
  • 66
  • 75
  • 101
Eyal
  • 1
  • 1
  • 2 comments: 1. the revert message in the first require is "The battle isn't exist" and not "Battle number isn't exist.\n". 2. It is possible to extract the message itself using substring, but I am looking for a simple way to separate the message and the address. – Eyal Jul 18 '21 at 05:30
  • Does this answer your question? [How to properly use revert reason in web3.js to show meaningful error message in UI](https://stackoverflow.com/questions/66878031/how-to-properly-use-revert-reason-in-web3-js-to-show-meaningful-error-message-in) – Petr Hejda Jul 18 '21 at 09:56
  • Thank you for your response, but no, this suggestion is relevant only for running locally over Ganache. As mentioned in https://ethereum.stackexchange.com/questions/92540/do-all-ethereum-networks-return-the-revert-reasons-as-a-message-field, it isn't the way to extract the revert message over the Rinkeby test network. – Eyal Jul 27 '21 at 11:10

0 Answers0