I expect to be able to calculate the balance of an account in this way: add up the value on all the incoming transactions, and subtract the value on all the outgoing transactions, then subtract all the fees paid.
When I use this method, though, I get a different balance from several other sources, like: eth.getBalance(account)
and Etherscan. Why?
An Example
I picked a random account that has this "issue."
All account transactions:
Let's rewrite these transaction values...
in python code:
inbound = ['10']
outbound = ['9', '0.92']
paid_fees = ['0.00045932', '0.010846898028', '0.00084084']
Account Balance:
So when we calculate the sum, I expect to get the same as the balance that Etherscan shows:
Instead, I get Decimal('0.067852941972')
from the following calculation:
from web3 import Web3
total = sum(Web3.toWei(income, 'ether') for income in inbound)
for ether_spent in outbound + paid_fees:
total -= Web3.toWei(ether_spent, 'ether')
total_ether = Web3.fromWei(total, 'ether')
print(total_ether)
What is this dark magic?
Did this account generate Ether out of thin air?