[Ethereum] how to know smart contract gas price and gas limit when deploying the contract using web3j

contract-developmentgo-ethereumsolidityweb3j

I am new to smart contracts and ethereum I am using web3j to deploy contracts on the private network
Following this as a guide
https://github.com/web3j/web3j

In the below section of code, it asks for gas limit and gas price of the contract

Web3j web3 = Web3j.build(new HttpService());  // defaults to http://localhost:8545/
Credentials credentials = WalletUtils.loadCredentials("password", "/path/to/walletfile");

YourSmartContract contract = YourSmartContract.deploy(
        <web3j>, <credentials>,
        GAS_PRICE, GAS_LIMIT,
        <param1>, ..., <paramN>).send();  // constructor params

how should I determine the GAS_PRICE, GAS_LIMIT?
before that, I was using ethereum wallet to deploy contract it automatically estimates the gas price and limit. I am a beginner i do not know gow to estimate gas price and limit without ethereum wallet ?

Best Answer

Gas price needs to be defined by you not too low to be picked up by the miners. It's basically a bidding war between you and the other people who want their transactions (including contract calls and contract deploys) mined.

Gas limit can be found out by first deploying the same contract on a test network or on one of the test networks. Make sure to add a bit more available gas (10%-20%) to make sure your transaction will not fail and you will not lose the transaction fee.

Related Topic