5
  const params = {
    to: '0xdbC0d76Fb1f2399b618FB29922dBC5cf763dd3d7',
    from: dbDeposit.depositAddress,
    value: balance,
    gas: 2000000,
    gasPrice: '234567897654321',
    nonce: 0
  };
  console.log(params);
  return web3.eth.signTransaction(params, myPrivateKey);

That's my code and I'm actually unsure as to how much gas and gasPrice to set. I understand that gasPrice is sort of an upper limit and gas is how much miners get to keep?

So how do I go about figuring out how much of each?

4 Answers 4

8

The amount you will pay for a transaction is gasPrice*gas, so gasPrice is exactly what the name indicates, is the price per 1 gas. The gas is a measure of how much computational work your transaction requires. You can omit these values and let the node select them if you do not know how to set it. The current gas price is 9000000000 yours is several orders of magnitude bigger.

Hope this helps,

5

By simulating the transaction or the call you'll be able to get a gas estimation you can put in the params object: https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethestimategas

the same goes for the gas price: https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethgasprice

5

As Jaime said gas price is the price you pay from computational work , ex - you have 1000 lines in your code and during transaction 500 lines gets executed then 500 will be the gas price (just a scenerio) , whereas gas limit is upper limit after which gas price computation stops.

i use gas price -- > 5000000 and gas limit --> 2000000000 for deploying and calling functions of smart contracts. This works fine for me.

0

You can use getGasPrice method for suggestion Gas price, and use estimateGas method for estimate Gas.

See this example:

//get suggestion Gas price
const suggestion_gas = await web3.eth.getGasPrice();

//get estimate Gas
const estimate_gas = await web3.eth.estimateGas({
    'from': address,
    'nonce': nonce,
    'to': token_address,
    'data': data,
});

//params for sign transaction
const txParams = {
    nonce: web3.utils.toHex(nonce),
    gasPrice: web3.utils.toHex(suggestion_gas),
    gasLimit: web3.utils.toHex(estimate_gas),
    maxPriorityFeePerGas: web3.utils.toHex(suggestion_gas),
    maxFeePerGas: web3.utils.toHex(suggestion_gas),
    to: token_address,
    value: '0x00',
    data: data,
    chainId: web3.utils.toHex(chainId),
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.