1

I want to set my custom gas and gas Price in sendTransaction method.Currently I set it but when i send the transaction gas fee is showing 0.21 ETH in metamask. How can I solve this?

web3.eth.sendTransaction({
   from: currentAccount,
   to: toAddress,
   value: web3.toWei(value, 'ether'),
   gasPrice: web3.toWei("0.00001" , 'ether'),
   gasLimit: '21000',
   chainId: '0x1'
}

Above is my code. How can I solve it?

1 Answer 1

2

Gas fee = gasLimit * gasPrice + value.

In your case, it is 21000 * 0.00001 + value.

The gas fee that metamask shows you implies that 21000 * 0.00001 + value == 0.21.

This implies that value == 0 (i.e., you are not sending any ether in the transaction).

Subsequently, the gas fee turns out as 21000 * 0.00001 + 0 == 0.21.

So there is no contradiction between what you set and what metamask shows you.

2
  • HI goodvibration, Thanks for your comment. I tried after setting Gas Fee but I am getting this error. Error: [ethjs-rpc] rpc error with payload {"id":1428479888420,"jsonrpc":"2.0","params":["0xf884029f307833386334326531382e363138363137303564363032643637343135376382520894b5ef36bda3c126f4046096635563d47f1517a1738609184e72a0008025a06fc330345fa4424dc4df326bc0f2869adb0c2e8f4cc4c7a32924dabea75fe2c8a05ac8c6c2e40a55a3689df03f3d422dd769e75db33fdf79153726212c4161d27a"],"method":"eth_sendRawTransaction"} [object Object]! Commented Mar 27, 2020 at 5:39
  • @AdilKadiyawala: That's a different question. Please post it separately, and if this one has answered your question, then please accept it by clicking on the V next to it. Commented Mar 27, 2020 at 6:03

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.