I have a smart contract with required message and pretend to use the required/validation message in front end.
require(bytes(hashAlreadyRegistered[hash]).length == 0, "Hash already registered");
I'm trying to get the reason of revert using web3.eth.call
.
By my understanding reading the doc if i pass the object generated by sendTransaction
it will work. I think it is what i'm trying to do but didn't work so far.
My codes
sendTransaction
method:
await canManipuleContract.methods.setDocumentHash('#_' + request.body.hash)
.send({
from: fromAddress,
gas: 400000,
gasPrice: 21000000000
})
.then(function(txRaw) {
console.log(txRaw)
return response.json( txRaw.transactionHash );
})
.catch(function(error) {
handleRevert(error);
console.log("Error: \n" + error);
return response.json( 'error' )
})
}
web3.eth.call
method:
function handleRevert( transactionObject ) {
web3.eth.call( transactionObject, function( err, result ) {
if ( ! err ) {
console.log( 'result ' + result )
}
console.log( 'err ' + err)
//return response.json( 'Error: Returned error: execution reverted' )
})
}
The return value of handleRevert
is always err 0x
. In geth console i clearly see the value err
and errdata
returning the correct messages.
If i pass the contract address
instead transactionObject
in web3.eth.call
method it always return Error: Returned error: execution reverted
, but never the required message it self.
Version:
Geth: 1.9.15-stable
web3.js: ^1.2.8
What am i missing here? Any others methods to get the message required of smart contract will help here.