Sai Chand Akella
Sai Chand Akella

Reputation: 11

How to read data from the block chain

I am new to implementing the blockchain locally. Suppose I have a blockchain,

Upvotes: 0

Views: 905

Answers (1)

JBaczuk
JBaczuk

Reputation: 14619

How to retrieve the data that is being chained in the blockchain.

You can store the data however you like. A blockchain is just a data structure similar to a linked list, nothing more. Thus, you can store it as flat file (which Bitcoin Core does), or in database, etc. Bitcoin also stores a LevelDB containing an index of the block files so it knows how and where to retrieve data for a given block. It can also be configured to store an index of every transaction by txid using the -txindex flag at startup of bitcoind.

Is it that only the transaction IDs are saved in the blockchain like the hashes or the actual data being stored in the network.

The blockchain contains all of the transactions that have every occurred on the network. This way all transactions can be validated by all of the participants on the network to make sure there was no double spending, etc. Otherwise you don't know if the coins you received are valid.

How can I retrieve the data if the latter is the case?

How do you want to be able to retrieve the data? If you want to be able to search by block number or block hash, for example, just index the data by block number or block hash. That way you can quickly query the dataset (the blockchain) by block number/hash.

If you want to be able to search for specific transactions, then just index it by txid.

Upvotes: 1

Related Questions