Blockchain Data Analytics For Dummies. Michael G. Solomon

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

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

Blockchain Data Analytics For Dummies - Michael G. Solomon

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

id="ulink_a6061054-fdb3-538b-908a-f1c0dffbde36">Etherscan can decode the input data for you. Click or tap the Decode Input Data button and Etherscan will try to translate the input data into easy-to-read input parameters for the called function. Figure 3-8 shows successfully decoded data for the cancelOrder() function. (In Figure 3-4, you saw that this transaction calls the cancelOrder() smart contract function.)

Screenshot of a successfully decoded data for the cancelOrder() function, in Etherscan.

      FIGURE 3-8: Decoded data for the cancelOrder() function.

      You don't get this level of detail in every transaction. This transaction called a function in a registered smart contract. Registering a smart contract means that the developer submitted the application binary interface (ABI) for the contract, along with the compiled bytecode. An ABI is a definition of a smart contract’s state data, events, and functions, including each function’s input and return parameters. Etherscan uses the ABI, if it is available, to provide more descriptive information. If the ABI is not available, Etherscan can display only the raw input data.

If you explore the Etherscan page, you’ll notice the Event Logs, State Changes, and Comments tabs. I don’t cover those here, but I do revisit them in Chapter 6. Transaction data isn’t the only data you’ll encounter in a blockchain application. Smart contract developers commonly use events to log notable actions in a smart contract. Data from these events are often of interest in the data analysis process. You’ll see this type of data again.

      You’ve already seen most of the types of data you’ll use when carrying out blockchain analytics. You’ve seen block header data, basic transaction data, and details contained in some transactions. You may have investigated the Etherscan user interface to view some event data, and even the effect a transaction has on the blockchain state. In this section, you learn more about the main categories of blockchain app data: transaction, events, and state.

      Serializing transaction data

      The core of blockchain data is contained in the transaction. A blockchain transaction records the transfer of some value from one account to another account. Additional information may be in the transaction, such as input data that records smart contract parameters, but not every transaction includes additional data.

      Each transaction does include a timestamp showing the date and time the transaction was mined, so you can create a chronological list of transactions and see how value changed ownership at specific points in time and how value moved among accounts. This movement is serial. The serial nature of data storage can yield interesting information but can also be an obstacle to analyzing the data.

      Unlike traditional data storage systems such as relational databases, final tallies or balances often have to be calculated over time. A traditional database can store the current balance of an account, while you may have to trace all blockchain transactions for an account to arrive at its final balance. The data is available, but it may take more work to get to it.

      If you're comfortable with databases and applications that access database data, searching transactions doesn’t sound like such a bad thing to do. However, remember that a blockchain is not a database. The data in a blockchain is not stored in a manner that makes general purpose queries easy and fast. You can get the information you want, but you have to think about the effort to get that data in a different way.

      The serialized transaction storage of blockchain data does provide the flexibility to trace and retrieve activity data in several ways. Here are a few types of queries you can satisfy by tracing blockchain transactions:

       Find all transactions in which a specific account sent funds.

       Find all transactions that resulted in a specific account receiving funds.

       Find all transactions that occurred between two specific accounts.

       Find all transactions that invoked a specific smart contract function.

      After you fetch the data you want, you can trace the transactions, calculating the value change (that is, keeping track of the Value and Transaction Fee fields) to find the information you’re looking for, such as a balance at a specific point.

      Logging events on the blockchain

      One of the more interesting aspects of blockchain data extends the information you can get from transactions. As mentioned, a transaction is the transfer of some value as a result of a smart contract function. Because the only way to create a transaction is to invoke a smart contract function, you can be sure that a transaction is the result of a function.

      The previous statement may sound redundant, but it's extremely important. Smart contract functions can be simple or complex. As smart contracts become more complex, just knowing the function a transaction invoked, along with its input parameter values, isn’t always enough information to describe what’s going on. You need a way to record what happens inside transactions.

Ethereum, and most popular blockchains second generation and beyond, support sophisticated smart contract languages. Ethereum’s EVM (Ethereum virtual machine) is a Turing complete machine, so with enough resources, an Ethereum smart contract can calculate anything. Of course, in the real world, transactions eventually run out of gas, but the point is that your smart contract functions can be as complex as you want.

Screenshot displaying the last two events for a current transaction in block 8976776 that occurred during a smart contract function.

      FIGURE 3-9: Ethereum events in Etherscan.

      Note that these events have names — LogTransfer() and LogOrderCancelled() — and parameters. Smart contract programmers use events to create messages that Ethereum logs and saves. Events make it easy to notify client applications that certain actions have taken place in a smart contract and also to store important information related to a transaction.

      

Smart contract programmers

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