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

Way to estimate gas before execute #2736

Open
Nafidinara opened this issue Dec 20, 2024 · 1 comment
Open

Way to estimate gas before execute #2736

Nafidinara opened this issue Dec 20, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Nafidinara
Copy link

Problem

Hello, is there any way to calculate gas in Hashgraph SDK like in web3js?

web:

myContract.methods.SetMessage(_message)
    .estimateGas(
        {
            from: _from,
            gasPrice: _gasPrice
        }, function(error, estimatedGas) {
        }
    )
});

I want to implement here,
hashgraph:

const contractExecTx = new ContractExecuteTransaction()
            .setContractId(contractId) 
            .setGas(300000) // I want to estimate the gas value to put here
            .setPayableAmount(payableAmount)
            .setFunction(method, functionParams);

Solution

  • add estimate gas method

Alternatives

No response

@Nafidinara Nafidinara added the enhancement New feature or request label Dec 20, 2024
@ivaylonikolov7
Copy link
Contributor

If I understood you correctly, we are currently working on this functionality. You can check it here - #2670. It will be released in the next stable version which is going to be somewhere in the beginning of January.

There is a way for you to get the exact gas cost by sending a POST request to Mirror Node but I would highly recommend you to wait for our next stable release which is going to make your job much easier and you wouldn't have to deal with any issues you may find if you try to implement it yourself.

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

No branches or pull requests

2 participants