I just started getting interested in the blockchain a week ago, however there is something I can not just figure out.

Regarding the flag "Spent/Unspent" in transactions. I get that we flag "spent" the output of a transaction if this same output is used as an input in a future transaction.

-Suppose that we make a transaction (transaction 1), and this transaction get included in the blockchain (let's say block 1). We do not spent the output (consider a simple transaction single input & a single output) until 100 blocks later (transaction 2) in the blockchain.

I understand that in transaction 2, in the inputs, there is the info of the previous transactions (since we are implementing hash pointers)like shown below in "prev_out" (JSON format of transaction extracted from Blockexplorer api) :

'inputs': [{'prev_out': {'addr': '1PFtrRjbq4aLfM7k4tyLZ3ZAuTsgLr6Q8Q',
    'n': 0,
    'script': '76a914f423dfee34e4833104508103d89e316b4a49314088ac',
    'spent': True,
    'tx_index': 356882858,

Up to now, there is no problem, I can totally understand that we can add a flag spent/unspent for the previous outputs (inputs) in transaction 2.

Suppose now this is the output of transaction 1 (which we are going to spent 100 blocks later).

By the way, this is a real transaction, its hash: a117a7aab7e2db8ef5fd40e74f72d689e13b733136454d2340a244236fbed9eb

'out': {'addr': '1PFtrRjbq4aLfM7k4tyLZ3ZAuTsgLr6Q8Q',
   'n': 0,
   'script': '76a914f423dfee34e4833104508103d89e316b4a49314088ac',
   'spent': True,
   'tx_index': 356893407,
   'type': 0,
   'value': 16351264}

My question is: You can see that the flag "spent" is True, How is this even possible ? Because during 99 blocks the transaction was unspent (flag=False). There is only one case possible for the flag "spent" to be True:

-The transaction 2 has to be in the same block as transaction 1. Otherwise if transaction 2 is in block 100 and the flag "Spent" of transaction 1 is True, it means that:

For 99 Blocks the flag was False and in the block 100, we change the flag of transaction 1, which is in block 1.

That means that we changed block 1, hence changed its hash --> impossible given the structure of the Blockchain.

Thank you for enlightening me !

1 Answer 1


It is important to understand that the spent flag you are talking about, is not a field of an output that is stored in the blockchain. It is rather created internally by the client interacting with the blockchain. The only fields of information of an output that is permanently stored on the blockchain are:

  • The Amount
  • The Locking-Script Size
  • The Locking-Script

All the full nodes on the bitcoin network checks if an output is spent or not by checking if the output is part of a structure called the UTXO set. In this structures all nodes keep all outputs which has not yet been spent at the last block of the blockchain the nodes have validated. If an output is part of the UTXO set, it means that the output is unspent.

For every new block in the blockchain, the nodes validates the block and removes any previous outputs in the UTXO set, that has been used as inputs in the new block.

Since a new node validates the blockchain by starting from the first block ever, called the genesis block, and updates UTXO set for every block in the blockchain, the UTXO set will contain all current unspent outputs once the node is synced with the rest of the network.


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.