0

Is it clear that for every "ether" transfer using "address.transfer(amount)" how much "fee" must be paid? I mean how much is the cost of transferring ether by address.transfer(amount)? Is it a fix value for this transaction fee? And is fee difference with the gas price of a transaction ? Here is mentioned that

"Only a small amount of gas is sent along (21000 gas)."

Does it mean the transaction fee is 21000 wei ?

1 Answer 1

1

address.transfer will use about 9000 gas, and set a gas limit of 2300 gas. This means that if the transfer is to another contract, only 2300 gas are available to executions code in the target contract.

The 21000 thousand is the base cost of transaction started by user owned accounts (UOA) transferring ether from a UOA to another UOA cost 21000 and to a contract the base cost is also 21000. plus the cost of executing the contract code.

address.transfer is a message call, inside a transaction so if your execute a function that contains address.transfer you will pay the 21000 gas plus the 9000 gas (approx).

Hope this helps

5
  • Thank you, when you say "21000 gas plus 9000 gas" does it mean 21000 wei plus 9000 wei ? Btw, is there a reference for this cost in solidity.readthedocs.io ? Thanks
    – Questioner
    Jul 18, 2018 at 11:52
  • 1
    Gas is a measure of the computational cost, you need to multiply it by the gas price to get the ether value. Currently, the gas price (it changes) is 2100000000 wei, so 21000 gas cost 21000*2100000000 = 0.00004 eth or 0.022 USD. See this. The info about the gas cost can be found in the yellow paper appendix G, page 25. The 9000 value is from experience, I had the same question as you some time ago and ran some code to estimate the gas cost of address.tranfer and I end up with 9000 as a good estimate.
    – Jaime
    Jul 18, 2018 at 13:14
  • Thank you, and where is written "Std Cost for Transfer" (top - left) does it mean that for every time we send ether using address.transfer(amount) it cost $0.042 ? Thanks
    – Questioner
    Jul 18, 2018 at 13:34
  • 1
    No, sending ether normally will always cost 21000 gas, the price depends on the gas price and the gas price changes depending on the network's status. Also, when you send ether from your wallet you are not doing address.transfer(amount). address.transfer(amount) is a method used to send ether from a contract to user accounts or other contracts. If you execute the contract that runs that method you will pay the base cost for any transaction (21000 gas) plus the gas that is spent running the code. Again, the total cost will be gas used multiplied by the gas price. I hope this is clear
    – Jaime
    Jul 18, 2018 at 13:46
  • I understand the purpose of 21000. Would you please let me know what is the purpose of 9000 gas ? Thanks
    – Questioner
    Jul 24, 2018 at 10:02

Your Answer

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

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