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

Add a query to estimate the gas of a contract call #878

Merged

Conversation

gsstoykov
Copy link
Contributor

@gsstoykov gsstoykov commented Jan 14, 2025

Description:

A new MirrorNodeContractQuery class has been introduced to support EVM gas estimation and simulation. This query class provides two distinct types of queries:

  1. MirrorNodeContractCallQuery – Executes a contract call and returns the result, simulating the execution of the contract.
  2. MirrorNodeContractEstimateGasQuery – Estimates the gas usage for a contract call, allowing developers to understand the cost of executing a transaction.

The inputs for these queries match those of ContractExecuteTransaction, making it easy for developers to calculate the cost of a follow-up transaction.

The MirrorNodeContractQuery issues an HTTP request to the api/v1/contracts/call endpoint of the Mirror Node Web3 module, which supports both gas estimation and transient simulation of state-changing transactions. This enables accurate cost predictions and helps developers optimise their contract interactions before executing them on the network.

Related issue(s):

Fixes #841

Notes for reviewer:
Design was agreed upon from discussions for Java/GO but could be reworked in the future as it is not fully extendable. The C++ SDK implements the design so it aligns with the other SDKs.

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@gsstoykov gsstoykov linked an issue Jan 14, 2025 that may be closed by this pull request
@gsstoykov gsstoykov changed the title 00841 add a query to estimate the gas of a contract call (WIP) Add a query to estimate the gas of a contract call Jan 14, 2025
@gsstoykov gsstoykov changed the title (WIP) Add a query to estimate the gas of a contract call Add a query to estimate the gas of a contract call Jan 21, 2025
@gsstoykov gsstoykov self-assigned this Jan 22, 2025
@gsstoykov gsstoykov marked this pull request as ready for review January 22, 2025 12:34
@gsstoykov gsstoykov requested review from a team as code owners January 22, 2025 12:34
Copy link
Contributor

@rwalworth rwalworth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@gsstoykov gsstoykov merged commit 8a13c74 into main Jan 24, 2025
5 checks passed
@gsstoykov gsstoykov deleted the 00841-add-a-query-to-estimate-the-gas-of-a-contract-call branch January 24, 2025 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a query to estimate the gas of a contract call
2 participants