In my App.js I have called the smart contract function and the require statement in the function is not satisfied, so how do I get the message of that require statement in my App.js?
Web3 1.2.5 supports the revert messages now, activated by setting
web3.eth.handleRevert = true. You can use
TestContract.methods.myMethod(myParam).call().catch(console.log) to receive the message without sending the transaction.
See https://soliditydeveloper.com/web3-1-2-5-revert-reason-strings for more details.
You should probably ask yourself how else would the transaction revert without being executed.
It doesn't change any of the state variables which the contract function is designated to.
But it is still executed to the point where the
require statement is rejected, and a REVERT opcode along with the error-message is sent from the node back to your application.
If you're communicating with the node via web3.js, then the latter typically throws an exception with an error-message which starts with
"VM Exception while processing transaction: revert" and ends with the error-message of the