0

In a solidity method, there is a require statement which is being failed and transaction in web3j is throwing error as "Gas value is not enough".

Example: require(providedtimestamp > block.timestamp, "release time is before current time");

But in transactions from Etherscan, the error message is correctly displayed. Example: https://rinkeby.etherscan.io/tx/0x2ed757feef430f1695dcbbad8d13ee8df5ba630409465dbf82688dc5543dc52e

How to catch this error message during the method call using web3j.

Sravan Kumar
  • 41
  • 2
  • 6

2 Answers2

0

you can easily call the function and do a catch like this:

contract.function.call({from:accounts[1]}).then((result) => {
  console.log("Success! Got result: " + result);
}).catch((err) => {
  console.log("Failed with error: " + err);
});
Jacopo Mosconi
  • 972
  • 8
  • 22
0

You should use try/catch to get an error description when an exception occures using web3.java.

try {
  TransactionReceipt balanceOf = test.transfer(new Address(address), transferBalance).get(); 
} catch (Exception e) {
  // Extract error string from exception
}