1

This question already has an answer here:

I wanna understand how can a user find a certain transaction he created on the blockchain without him knowing on which block it belongs ? does he have to go over all the blocks using bloom filters to find his transaction ? narrow the search to an interval of timestamps ? there must be a special mechanism ...

I searched on google but all i found were websites to find them for u, i want to understand the actual mechanism used in the bitcoin protocol?

Block Explorers seems to be storing those transactions in special databases and they use their own approach to find transactions ... My question is about how full nodes find those transactions ? do they go over the whole chain trying to find them ?

marked as duplicate by Rutger Versteegden, RedGrittyBrick, Pieter Wuille, Andrew Chow Jul 13 at 16:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Are you asking about how to search for a transaction using Bitcoin Core? There is an RPC for that, assuming you enabled indexing. Or are you asking how Bitcoin Core does it? Bitcoin and Ethereum will be different, but you can visit ethereum.stackexchange.com – JBaczuk Jul 1 at 17:41
  • About how Bitcoin core does it – rachid chami Jul 1 at 19:16
  • Bitcoin Core does not do this. It has a database of unspent outputs, and adds/removes outputs from that database. It (generally) does not have an index into the blockchain, or even the entire blockchain at all available. – Pieter Wuille Jul 1 at 19:43
  • Then my question is, how websites like block explorer works. – rachid chami Jul 1 at 20:18
  • Seems like it was covered in here bitcoin.stackexchange.com/questions/58844/… but without great details or how exactly it works, just the general idea behind. But apparently, there isnt any native mechanism to the protocol that lets u search in blocks, u just need to go over all the blocks and search for transactions (in Eth, using bloom filters to know if a certain transaction belongs) in a way or another. – rachid chami Jul 1 at 20:27
1

After searching about this, i found out that each full node maintains a database with the set of unspent transaction outputs (UTXOs) in the memory. So When a new transaction is added, its UTXOs get updated accordingly (source). Also, a full node keeps track of all transactions that ever happened (source) and offer this:

Filtering transactions and blocks on behalf of lightweight nodes so that lightweight nodes do not need to download every transaction ever made on the network in order to find their own transactions.

Serving historical full blocks to nodes that have been offline for a while.

Transmitting new transactions from users to miners.

Broadcasting new blocks from miners to other nodes.

The RPC used for this call getrawtransaction that takes as an argument a TxID which is hashing twice the transaction data and gives you back the transaction you are searching for.

  • "NOTE: By default this function only works for mempool transactions. If the -txindex option is enabled, it also works for blockchain transactions." – JBaczuk Jul 2 at 20:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.