1

It seems like the blockchain transactions only stores the number of coins moving from one wallet to the other, but does not have the total amounts for each wallet.

Therefore it seems like if you want to get the value of any given wallet you would have to read every transaction in the ledger from the very beginning.

Is this correct or am I missing something?

Fyi, my goal is to understand the format of the blockchain better

3 Answers 3

3

Assuming you don't trust anyone, you need to read the entire blockchain history once to generate your own set of unspent transactions (UTXOs). You won't need then to read again the full history every time you want to see your balance. Unspent Transactions are enough to do so.

Your balance is the sum of the values of the unspent transactions your wallet has. Unspent means here that you didn't "spend" the previously received amounts on outgoing transactions.

Example:

  • Alice sends you 1 BTC. you now have an unspent transaction of 1 BTC. Your balance is the sum of unspent transactions, i.e. 1 BTC
  • Then Bob decides to send you 2 BTC. You have now two unspent transactions associated to your wallet, for a total balance of 3 BTC.
  • Let's assume now you want to send 1 BTC to Charlie. After checking that you have at least 1 unspent BTC (which is the case), your transaction would be processed and the amount that you spend would be removed from your "unspent" transaction. In that case, the transaction received from Alice would be now marked as spent and would be removed from your list of unspent transactions.
  • Your balance is still the sum of unspent transactions, i.e. 2 BTC (from Bob)
1
  • 1
    In order to figure out what the unspent outputs are, you still need to read the entire blockchain history.
    – Ava Chow
    Commented Feb 23, 2018 at 4:18
2

If it is your 'wallet' and you have the private keys then you can import them into a wallet application. The wallet, with some work, is able to decipher which addresses are yours, scan the transactions on the blockchain and, update the balances.

1
  • I mean to ask how would one write software to do this? I'm trying to understand the format of the blockchain
    – Zain Rizvi
    Commented Feb 22, 2018 at 12:43
1

Therefore it seems like if you want to get the value of any given wallet you would have to read every transaction in the ledger from the very beginning.

Yes, basically. If you were sent 1 BTC in 2010 and never spent it, and 1 BTC in 2018 (also unspent), you have 2 BTC, but without going through the entire history of the ledger, you wouldn't be able to see both in your wallet without scanning the entire history.

It would be nice to be able to bootstrap a node with just the UTXO (unspent coins) at some point, but then to do this you'd have to trust the person generating the bootstrap, and you could not trace the true history of any of the coins (such as what IOTA do when they take a snapshot).

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.