4

I'm trying to figure out how to send an entire address balance in a post EIP-1559 transaction (essentially emptying the wallet). Before the London fork, I could get the actual value as Total balance - (gasPrice * gas), but now it's impossible to know the exact remaining balance after the transaction fees because the base fee is not known beforehand.

Is there an algorithm that would get me as close to the actual balance without going over? My end goal is to minimize the remaining Ether balance, which is essentially going to be wasted.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Proto Ukr
  • 492
  • 4
  • 13

1 Answers1

2

This can be done by setting the 'Max Fee' and the 'Max Priority Fee' to the same value. This will then use a deterministic amount of gas. Just be sure to set it high enough - comfortably well over and above the estimated 'Base Fee' to ensure it does not get stuck.

Mark B
  • 52
  • 2
  • thanks for your suggestion. I have a question -- how is this proposed method different from specifying the gas price before the London fork? I mean, if I set 'max priority fee' to be the same as 'max fee', then it will always use 'max fee'. So, it will be a static amount just as the gas price. Would it be correct to say that we cannot minimize the fee and at the same time make sure the whole wallet is spent? It's either one or another, correct? – Proto Ukr Nov 22 '21 at 23:08
  • Another observation. Since the London fork has backward compatibility, I can still use 'gas price' to set the fee amount I'm willing to pay. So, setting 'max priority fee' to 'max fee' or simply using 'gas price' will result in the same outcome. Please correct me if I'm wrong. – Proto Ukr Nov 22 '21 at 23:13
  • 1
    @ProtoUkr How can you get the base fee before sending the transaction? You need the base fee to calculate the value (`value = balance - (baseFee + tip)`) – httpete Jan 05 '22 at 12:15
  • Even if you know the next base fee, you could miss the block and the next base fee could be lower. This would leave some ether in your wallet. – Bert Kellerman Jul 05 '22 at 19:29