Blockchain Data Analytics For Dummies. Michael G. Solomon

Blockchain Data Analytics For Dummies - Michael G. Solomon


Скачать книгу
processes

      Many descriptions of blockchain technology relate it to well-known data storage techniques. One of the more popular descriptions states that a blockchain is essentially a distributed ledger of transactions. This description is somewhat true but overly simplified. A blockchain does store transactions like a ledger and is distributed, but it contains far more interesting information. If a blockchain only stored transactions it wouldn’t be very interesting because it would be little more than a distributed spreadsheet.

      A blockchain is far more than just a distributed spreadsheet — it contains an indelible record of the data’s current state (current values) and a complete historical record of how the data came to the current state. Traditional data repositories generally store only the final state of data. As you make changes, those changes overwrite any previous values. More sophisticated data repositories maintain audit records, which are generally external notes that record changes to data values.

      Additionally, blockchain apps can create logging entries that document events that occur as smart contracts execute. The ability to record activities can provide a view of how data changes, not just the fact that it did change. And finally, each block in a blockchain stores information about the functions — and input parameters — in a smart contract that an application calls.

      In this section, you discover what data gets stored in blocks on a blockchain. Although each blockchain implementation differs in its low-level details, the concepts are generally consistent across blockchain types.

      Because the purpose of this book is to introduce you to the most important concepts of blockchain analytics, I won’t cover the specific technical details of every blockchain. Instead, you learn about the specific features of the most popular public blockchain implementation, Ethereum. If you don't use Ethereum, don’t worry — the concepts you learn here will apply easily to any other blockchain implementation.

      

The main difference between the most popular types of blockchain is the way in which they handle transactions. Bitcoin uses the Unspent Transaction Output (UTXO) model, in which each transaction spends some of what was leftover from a previous transaction, and then creates new output that is the remaining (unspent) balance after processing a transaction. The other main approach to handling transactions is the Account/Balance model, which Ethereum uses. In the Account/Balance model, each account has a recorded balance, and transactions add to, or subtract from, that balance. The Account/Balance model is similar to a traditional ledger. I focus on Ethereum and the Account/Balance model in this book.

      Understanding what's stored in blockchain blocks

      As mentioned in Chapter 2, blockchain is just a specially constructed group of blocks that are linked, or chained, to one another. Each block header contains the hash of the previous block, forming the link that creates the chain. From many descriptions, it sounds like the blocks in a blockchain are pretty much the same as the data in a database or other data repository. However, that view isn’t accurate. Blockchain stores a lot more than just values of data items, which is why blockchain analytics is so interesting. A lot of information is in a blockchain, but you need to know how to get to it.

      Recording transaction data

      Regardless of the approach used to create new blocks, blocks generally contain transactions or smart contract code. Because blockchain technology was introduced to manage cryptocurrency, it stands to reason that transaction data focuses on transferring ownership from one address to another. In this section, you look at a block to see its header information and a list of transactions.

Screenshot of a portion of Etherscan’s block header information. The block examined is block number 8976776, which contains 95 transactions.

      FIGURE 3-1: Viewing block header information in Etherscan.

      To find block 8976776 in Etherscan, go to https://etherscan.io/ and enter the block number in the All Filters field. Then click or tap the search icon (magnifying glass).

      

Etherscan does much more than provide a way to peek at data on Ethereum’s mainnet. You can examine and retrieve data from mainnet; popular testnets including Ropsten, Kovan, Rinkeby, and Goerli; and the Energy Web Foundation (EWF) chain. If you create an account and request a free API key, you can use the key to extract blockchain data.

Screenshot depicting the first 5 transactions in block 8976776; each transaction has a From account, a To account, and an amount listed out.

      FIGURE 3-2: Listing transactions in a block in Etherscan.

Screenshot of transaction details page in Etherscan. The initial page depicts general information about the Ethereum transaction and the To field shows that the target address is Contract.

      FIGURE 3-3: Examining a transaction in Etherscan.

In Ethereum, the only way you can access data stored in the blockchain is through a smart contract. You use the smart contract’s address (where the smart contract code is stored in the blockchain) to run, or invoke, one of its functions. Smart contract functions contain the instructions for accessing blockchain data.


Скачать книгу