2

How are gas fees calculated in account based model coins like ETH?

Let's say I own 10 ETH addresses with 0 starting balance. I receive 0.1 ETH payment from 10 people - each one sending a payment of 0.1 to one of my 10 ETH addresses (Obviously in 10 separate transactions). The combined total in all 10 addresses I own is now equal to exactly 1 ETH.

I now want to "forward" (consolidate) all 10 payments received to a single ETH address under my control. According to EtherScan it costs approx. 40 gwei (or $0.90) for the transaction to be confirmed in 16 min (slowest confirmation time). Assume I chose to forward all 10 payments using 16 min confirmation time. My impression is that the combined fee should be calculated as 10 * $0.90 (or 1- * 40 gewi * 21,000) which is equal to $9. Is this correct?

If, after forwarding ("consolidating") the entire amount to one address, I now want to transfer that amount (1 ETH) to another address (single output), the fee for this transfer would only be $0.90 cents, correct (since all ETH is now originating from a single address)?

If instead of sending 1 ETH to one address, I split it between two ETH addresses (so 0.5 ETH to each address) the cost is calculated as 2 * $0.90 cents or $1.8 total or is it one fee of $0.90?

Assuming my calculation above is accurate, does the calculation change if I transferred the original 10 * 0.1 payment to the single ETH address via a single batch transaction vs. if they were transferred in 10 different transaction? My impression is that since ETH uses an account based model there's no concept of batch transfers. So whether the original 10 * 0.1 were transferred at one time vs multiple occasions/times - it would not effect the fee I pay when transferring 1 ETH to another address. Is this correct?

I hope the question is not too basic as I searched and could not find a definitive answer.

14
  • A gas-price of 40 gwei means 40 gwei per gas unit. Transferring ether to an EOA costs 21000 gas units, hence 40 * 21000 * 10 ^ 9 wei. Jan 13, 2021 at 18:23
  • And since wei = 1 / 10 ^ 18 ether, the actual cost of transferring ether to an EOA is 40 * 21000 / 10 ^ 9 ether. Jan 13, 2021 at 18:26
  • No. Please read the explanation again. Jan 13, 2021 at 19:32
  • @goodvibration There are 1 billion gwei in 1 ETH. 40 gwei * 21,000 gas units = 840,000 gwei. If the exchange rate of 1 ETH = $1,000 USD then the cost for a single transaction can be calculated as (1,000 divided by 1 billion) -> 0.000001 and 0.000001 * 840000 = $0.84. For 10 transactions the cost would be $0.84 * 10 = $8.4. Is my thinking correct? If not kindly explain at which point in my calculation I erred. Thanks!
    – S.O.S
    Jan 14, 2021 at 5:54
  • WEI cost: 21000 * 40 * 10**9 = 840000e+9. Jan 14, 2021 at 6:05

1 Answer 1

2
+50

You are mostly correct in your analysis. Sending ETH from account A to account B will always cost (21000 * gasPrice). If you send ETH from account A to account B and C, you will have to do 2 transactions - A to B, then A to C. So you will pay twice as more fees (2 * 21000 * gasPrice).

Examples:

From A To B, C and D - 3 transactions (A-B, A-C, A-D), so 3 times the fee

From A To B - 1 transaction (A-B), so 1 time the fee

From A and B To C - 2 transactions (A-C, B-C) so 2 times the fee

However, contrary to what I just wrote, it is possible to send ETH from one account to N accounts and pay less than N times the fee per transaction (what you call a batch transfer). To do so, instead of sending the ETH from account A to all the N accounts directly, you must send the ETH from account A to a smart contract (DApp) that will handle the distribution to multiple accounts in a single transaction.

I read about disperse.app that is supposed to do exactly that, but I have not used it myself so do you own due diligence before using this service if you ever do. However, according to this post, you would only save gas on transactions that send ETH to accounts that have already been initialized. For brand new accounts, the gas cost is 25000 instead of the regular 21000 when doing a direct ether transfer. Sending ether from the DApp to existing accounts costs either 5000 or 20000 gas depending on whether the receiving address already has a balance or not, which is better than the regular 21000. I did not test this myself and only read about it in the above post.

You can estimate the gas of calling a DApp function by different methods. If calling the contract from Metamask, Metamask provides a generally accurate estimate of the gas you will pay just before confirming the transaction. If you are using web3.js to call the DApp, you should use the estimateGas() function. In all cases, you have to multiply the gas amount by the gas price in WEI to get the total cost in WEI that you will pay to call the DApp.

5
  • Thanks. Hope to award you the bounty later today. If you can kindly update your reply by addressing the following: 1) When sending ETH to account A from accounts X, Y and Z (3 separate transactions) I know I will have to pay 3 x fees to get the funds into account A. But if I now want to transfer said funds from account A to account B (one transaction) I would pay only one fee, correct? (In Bitcoin/UTXO model this would clearly be 3 fees so I want to confirm it is NOT so with ETH) 2) When sending funds from one account to N accounts via smart contract (DApp) what is a good way to (continued)
    – S.O.S
    Jan 21, 2021 at 16:53
  • (continued) calculate the estimated savings? 3) Finally, I think I read that the gas fees varies based on whether the EOA already has funds or is new. Is this correct? If so, could you explain how one would calculate the cost when the EOA has funds in scenarios mentioned in my question? Thanks!
    – S.O.S
    Jan 21, 2021 at 16:55
  • I edited the answer following your comments. Let me know if it helps!
    – Undead8
    Jan 22, 2021 at 13:42
  • Thanks for the update. The updated answer definitely helped (upvoted!). The only thing I wish to clarify further is that in the 3rd example "From A and B To C - 2 transactions (A-C, B-C) so 2 times the fee" If I now transfer from Account C to account X I only have to pay one fee even though the funds were deposited to Account C in two transactions (In Bitcoin this would use two UTXO so 2 * transaction fee but since ETH uses account based model I think it is only 1 fee). I think this is probably obvious but wanted to confirm nonetheless..
    – S.O.S
    Jan 22, 2021 at 18:16
  • 1
    Yes, in your example account C to account X would be only 1 transaction, so 1 time the fee.
    – Undead8
    Jan 22, 2021 at 19:53

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.