Blockchain Data Analytics For Dummies. Michael G. Solomon

Чтение книги онлайн.

Читать онлайн книгу Blockchain Data Analytics For Dummies - Michael G. Solomon страница 19

Blockchain Data Analytics For Dummies - Michael G. Solomon

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

mechanism called Kafka by default, but that can be changed if desired. Kafka depends on current nodes electing a leader, and that leader has the authority to build blocks of transactions.

      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.

Screenshot displaying the expanded transaction details page in Etherscan with additional information about a smart contract function call.

      FIGURE 3-4: Exploring additional transaction details in Etherscan.

      Dissecting the parts of a block

      Before you can start extracting data from a blockchain for analysis, you need to learn a little more about how the data you want is stored. Most of that data is stored in blocks, so that's what I discuss next.

      

Yes, that’s right! Most but not all data you’ll want for analytics is stored in blocks. Some blockchains, including Ethereum, store some data in an external, or off-chain, database. Don’t worry; I describe off-chain data too.

      

I describe only the basic Ethereum block and chain details. The authoritative reference for Ethereum internals is the Ethereum yellow paper, at https://ethereum.github.io/yellowpaper/paper.pdf. You can also find a good third-party detailed discussion of Ethereum block structure internals at https://ethereum.stackexchange.com/questions/268/ethereum-block-architecture.

      In Ethereum, the mining process uses the submitted block header and an arbitrary number called a nonce (number used once). The miner chooses a value for the nonce, which is part of the block header, and calculates a hash value using a hash function on the block header. The result has to match an agreed-upon pattern, which gets more difficult over time as miners get faster at mining blocks. If the first mining result doesn’t match the pattern, the miner chooses another nonce and calculates a hash on the new block header. This process continues until a miner finds a nonce that results in a hash that matches the pattern.

      The miner that finds the solution broadcasts that solution to the rest of the network. That miner collects a reward, in ETH (ether), for doing the hard work to validate the block. Because many miners work on blocks at the same time, it's common for several miners to solve the hash puzzle at almost the same time. In other blockchains, these blocks are discarded as orphans. In Ethereum, these blocks are called uncles. An uncle block is any successfully mined block that arrives after that block has already been accepted. Ethereum accepts uncle blocks and even provides a reward to the miner, but one that's smaller than the accepted block.

      

Ethereum rewards miners that solve uncle blocks to reduce mining centralization and to increase the security of the blockchain. Uncle rewards provide an incentive for smaller miners to participate. Otherwise, mining would be profitable only for large pools that could eventually

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