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