Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContractCallQuery does not expose ContractFunctionResult on error #1261

Closed
Nana-EC opened this issue Sep 13, 2022 · 1 comment · Fixed by #1281
Closed

ContractCallQuery does not expose ContractFunctionResult on error #1261

Nana-EC opened this issue Sep 13, 2022 · 1 comment · Fixed by #1281
Labels
enhancement New feature or request p1
Milestone

Comments

@Nana-EC
Copy link
Contributor

Nana-EC commented Sep 13, 2022

Problem

Unlike other queries ContractCallQuery can execute contract transaction logic even though it doesn't change state or get gossiped out.
As a result it's important to have more details regarding why a contract execution failed.
Currently the error details are limited to
{"name":"StatusError","status":"CONTRACT_REVERT_EXECUTED","transactionId":"[email protected]","message":"transaction [email protected] failed precheck with status CONTRACT_REVERT_EXECUTED"}

The network exposes this in the ContractFunctionResult which should be returned on all calls including failure as it includes the reason/error message.

It seems the java SDK exposes this but the logic is missing on the js version.
This results in eth devs who will predominately use the relay missing on the details they need to debug

Solution

Expose the ContractFunctionResult details on error.
Especially ContractFunctionResult.errorMessage
This will allow the relay to retrieve the information and pass it on to clients that submit contract call queries.

Alternatives

No response

@mehcode
Copy link
Contributor

mehcode commented Oct 3, 2022

After digging into this in the other SDKs, I can say that no SDK currently implements this.

In order to not break backwards-compatibility, we can't start not throwing an exception on a pre-check failure (CONTRACT_REVERT_EXECUTED). I'm going to add a nullable property contractFunctionResult to https://github.com/hashgraph/hedera-sdk-js/blob/main/src/PrecheckStatusError.js#L28.

Usage example:

let result;

try {
  result = await new ContractCallQuery()
            .setContractId(contract)
            .setQueryPayment(new Hbar(5))
            .setGas(75000)
            .setFunction("getMessage")
            .execute(env.client);
} catch (error) {
  if (error instanceof PrecheckStatusError) {
    if (error.status === Status.ContractRevertExecuted) {
       // do something with: error.contractFunctionResult
    }
  }

  throw error;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants