Fucntion in my contract:
function addMember (address _address, string _name, string _uniqueId) public{
require(bytes(members[_address].name).length==0, "member already added!");
require(msg.sender==admin, "only admin can add members!");
require(votingStart > now, "Can't register now; voting has already started!");
members[_address]=Member(_address, _name, _uniqueId);
}
I created java wrapper for the smart contract.
I am calling this function :
contract.addMember("499d44cea6797260e1f8166a60f7088f0cd13d7c", "dev01", "101")
I want to fetch error which is mentioned in require i.e.
member already added!
I am getting error:
Exception in thread "main" org.web3j.protocol.exceptions.TransactionException: Transaction has failed with status: 0x0. Gas used: 25668. (not-enough gas?)
at org.web3j.tx.Contract.executeTransaction(Contract.java:281)
at org.web3j.tx.Contract.executeTransaction(Contract.java:259)
at org.web3j.tx.Contract.executeTransaction(Contract.java:253)
at org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$3(Contract.java:305)
at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:30)
How can I get error that I mentioned in require. I don't think not-enough gas? exception happened here!
In executionTransaction method !receipt.isStatusOK() is checked and TransactionException with generic message is thrown.
Hi,
I think the ethereum network not support custom exception now.
If you really want the error message, you can write your own validation and let the transaction success, find the real status in the transaction logs.
I would change the require to an if and emit the relevant event which your application is listening for and can process.
Closing as this is not a web3j issue.
@iikirilov coment doesn't fix the original issue.
require is a much better and readable way to control errors and part of the Ethereum standard.
Also, maybe the contract has been developed by third parties and we have zero control over the source code.
In some scenarios the "if" approach is not even an option. For example if the function needs to return a value an that value can not be calculated until "later on" in the code.
This issue must be reopened if not yet solved.
Most helpful comment
@iikirilov coment doesn't fix the original issue.
require is a much better and readable way to control errors and part of the Ethereum standard.
Also, maybe the contract has been developed by third parties and we have zero control over the source code.
In some scenarios the "if" approach is not even an option. For example if the function needs to return a value an that value can not be calculated until "later on" in the code.
This issue must be reopened if not yet solved.