simolus3/web3dart

Any method to get error information of failed transaction?

Closed this issue · 3 comments

After sending a transaction, I can get the hashcode of the transaction, or an error from PRC. This is good, but I just found I cannot get the error information I provided by the 'require' function in smart contract.

Function in my contract is like this:

function bid() public payable openAuction {
require(msg.value > startPrice, "Please bid a higher amount.");
require(
msg.value > currentHighestBidding,
"Please bid a higher amount."
);
require(
msg.sender != owner,
"Can not bid for your own auction product!"
);
// some code to execute
...
}

While when I call this function by Web3Client.sendTransaction(), I got a transaction hash, and no error info shows up.

When I checked that transaction, I can find the fail status and error info: https://rinkeby.etherscan.io/tx/0xa81bbb105b2b2c46b4d0bf6c020fed21109dcccbb24290bdb169aa6ef562068f
Screen Shot 2021-03-08 at 10 31 23 AM

I tried to get TransactionReceipt, but I can still only get the status which is false, no error info. Is there any method I can get the error information in dart?

I think you can replay the transaction and get the error from there:

final info = await client.getTransactionByHash(
    '0xa81bbb105b2b2c46b4d0bf6c020fed21109dcccbb24290bdb169aa6ef562068f');
final result = await client.callRaw(
  sender: info.from,
  contract: info.to,
  data: info.input,
);

The call yields an RPCError: got code 3 with msg "execution reverted: Please bid a higher amount."..

@simolus3

I think you can replay the transaction and get the error from there:

final info = await client.getTransactionByHash(
    '0xa81bbb105b2b2c46b4d0bf6c020fed21109dcccbb24290bdb169aa6ef562068f');
final result = await client.callRaw(
  sender: info.from,
  contract: info.to,
  data: info.input,
);

The call yields an RPCError: got code 3 with msg "execution reverted: Please bid a higher amount."..

@simolus3 I am getting an exception while running it _CastError (type 'Null' is not a subtype of type 'String' in type cast)

@simolus3

I think you can replay the transaction and get the error from there:

final info = await client.getTransactionByHash(
    '0xa81bbb105b2b2c46b4d0bf6c020fed21109dcccbb24290bdb169aa6ef562068f');
final result = await client.callRaw(
  sender: info.from,
  contract: info.to,
  data: info.input,
);

The call yields an RPCError: got code 3 with msg "execution reverted: Please bid a higher amount."..

@simolus3 I am getting an exception while running it _CastError (type 'Null' is not a subtype of type 'String' in type cast)

image