I read from many questions (example: How to estimate the cost to call a Smart Contract method?) that web3.eth has a method estimateGas
that can provide an estimate of the gas usage of a transaction/function call.
I am trying to get an estimate for calling a function using my Java wrapper class generated by the web3j CLI.
Web3j web3 = Web3j.build(new HttpService(endpoint));
Credentials creds = Credentials.create(privateKey);
DefaultGasProvider gasProvider = new DefaultGasProvider();
MyNFT contract = MyNFT.load(contractAddress, web3, creds, gasProvider);
// I am interested in estimating how much gas the following call will use
TransactionReceipt receipt = contract.mintNFT(recipient, tokenUri).send();
How should I go about doing this in Java? Is there a Java equivalent for estimateGas
?