I want to get the revert massage from a send
method call to a smart contract. So I use: receipt.logs[0].data
that is a string containing a hexadecimal value.
Now I want to to decode this value to get the revert message. So I use web3.eth.abi.decodeParameter
method. The main problem is how to give type
parameter to get the proper message.
For example If I give:
const data = '0x0000000000000000000000000000000000000000000000000000c51ccda68b0000000000000000000000000000000000000000000000000002774a57aab99b34000000000000000000000000000000000000000000003692f60f63a91b794ce70000000000000000000000000000000000000000000000000276853add131034000000000000000000000000000000000000000000003692f61028c5e91fd7e7';
window.web3 = new Web3('https://rpc-mumbai.maticvigil.com');
window.ethereum.enable();
web3.eth.handleRevert = true;
let revertType = [{
type: 'string',
name: 'message'
}];
const reason = web3.eth.abi.decodeParameter(revertType, data);
console.log(reason);
It logs:
Uncaught (in promise) Error: invalid type (argument="type", value="messanger", code=INVALID_ARGUMENT, version=abi/5.7.0)
And if I use:
const data = '0x0000000000000000000000000000000000000000000000000000c51ccda68b0000000000000000000000000000000000000000000000000002774a57aab99b34000000000000000000000000000000000000000000003692f60f63a91b794ce70000000000000000000000000000000000000000000000000276853add131034000000000000000000000000000000000000000000003692f61028c5e91fd7e7';
window.web3 = new Web3('https://rpc-mumbai.maticvigil.com');
window.ethereum.enable();
web3.eth.handleRevert = true;
const reason = web3.eth.abi.decodeParameter('string', data);
console.log(reason);
It logs:
index.ts:269 Uncaught (in promise) Error: data out-of-bounds (length=0, offset=32, code=BUFFER_OVERRUN, version=abi/5.7.0)
The txHash in this example is 0x074e91fe5c1535d9bdc2bbc8cbadc0378c93eb06318401b1f341d844185430fb
on Mumbai Polygon testnet: https://mumbai.polygonscan.com/tx/0x074e91fe5c1535d9bdc2bbc8cbadc0378c93eb06318401b1f341d844185430fb