20 - Visualizing smart contracts
Throughout history, most great technological leaps are not obvious until they have impacted every facet of life. Perhaps this is because the first generation of any tech is usually rudimentary. The Bitcoin blockchain, for example, is one of the simplest versions of a blockchain. Being simple is not a bad thing. In fact, the Bitcoin network's simplicity helped to make it the titan it has become. It does one thing extremely well which is to ensure the authenticity of who owns what amount of bitcoin (BTC).
After authentic and immutable money tracking, Ethereum smart contracts are often cited as the next great blockchain innovation. The Yap’s, however, did not have the concept of a smart contract. The correlation between BTC and Yap can be easy to understand, while taking that one step further into the world of smart contracts can be somewhat confusing. Today we are going to discuss how to visualize blockchains with smart contract capabilities.
Smart contracts…. what are those again?
Quick refresher:smart contracts are automations created using code that perform a specific action when prompted. The example often used is that of a virtual vending machine. If you put a dollar and press “A1”, the machine returns a Snickers. In the world of blockchain smart contracts, if you send a digital asset such as ETH to the contract, the contract could return you another token, issue an NFT, or hold your ETH until a later date. The question becomes when we say “send to a smart contract,” what do we mean? Where is this smart contract, and how do we actually interact with it?
When discussing the Bitcoin network, blockchain.com was our tool of choice. If you want, you can go back to their site and easily switch from the Bitcoin block explorer to Ethereum's. We will not be exploring blockchain.com’s Ethereum block explorer which has less functionality than others on the market. Instead, we will be using etherscan.io as an alternative.
When you land on the etherscan.io home page, you find that it looks similar to the blockchain.com Bitcoin explorer. It has high level information about ETH such as ETH price, transaction volume, hash rate, and mining difficulty. The first two pieces of information are being pulled from an external source while the latter two are related to the Ethereum proof of work (PoW) consensus algorithm. In addition to this information, we also see the “Market cap” and “Med gas price.” Market cap is calculated as the total value of all ETH created multiplied by the current price per ETH and is often used to determine the total value of a blockchain network. Med gas price is a concept specific to the Ethereum network. If a user wants to transact on the Ethereum blockchain, they need to pay a network fee. That fee on the Ethereum network is called “gas” which is paid to the network miners. In the bitcoin network, a user also pays a transaction fee; however the term “gas” was something that was created with Ethereum. Since then, other networks have begun to adopt the term as well.
The second half of the screen shows the latest blocks and transactions. As you can see, this view is similar to the blockchain.com. One difference is the current block height. You can see on the left hand side for the latest block the block height of 14589933 is higher than the current Bitcoin block height of 731980. Even though Ethereum launched years after Bitcoin, its height is higher (meaning there have been more blocks created) because of the speed of block creation on the Ethereum network. Bitcoin makes blocks about every 10 minutes while Ethereum creates them about every 15 seconds.
When you click into a block like block 14589973, you will see the image above. Much of the information here is the same as Bitcoin, but a key difference is there are two categories of transactions: regular “transactions” and “contract internal transactions.” Regular transactions for this block total 43. These 43 transactions are transactions between a wallet owner and any other wallet owner or a wallet owner and a smart contract.
If you click on “43 transactions,” Etherscan will take you to a list of all the regular transactions in that block. The row headers help to categorize the data underneath. Below are what each of these headers mea
Txn Hash: Transaction hash for that particular transaction.
Method: Type of function happening. Ethereum and other networks allow for a variety of transactions including transfers and smart contract based transactions.
Block: The block height of the block in which the transaction is included.
Age: How long ago the transaction was added to the blockchain.
From: Who originated the transaction.
To: The wallet or smart contract address the transaction is going to.
Value: Total amount of digital assets being transferred.
Txn Fee: Amount the person sending the transaction must pay to the miner to have their transaction included in a particular block.
You can see the first few transactions are from one person to another. “Ethermine” is identified only because they identified themselves, and the transaction they are conducting is an asset transfer to an unidentified wallet. The last two transactions in the view are users interacting with the US Dollar Tether (USDT) smart contract. Etherscan has helped us understand this activity by both naming the contract “Tether: USDT Stablecoin” and providing a nice contract symbol in front of that moniker.
If instead you click on the “12 contract internal transactions,” you will be taken to a different page. The main difference between a regular transaction and a “Contract internal transaction” is that the latter is the byproduct of a “regular transaction” when that “regular transaction” includes a smart contract. As you can see in the “From” column, each of these “contract internal transactions” originated from a smart contract and only occur because a smart contract was triggered by a regular transaction. Etherscan also shows which original transaction triggered the “contract internal transaction” by providing the “parent txn hash.” The “parent transaction hash” will align with a “regular transaction” in the same block.
Visualizing smart contracts
We have just reviewed transactions involving a smart contract, but we have not actually viewed a smart contract. Smart contracts are similar to wallets in that they point to a location on a blockchain’s networks. Smart contracts have addresses which is how other wallet addresses can communicate with them. If you click on the first contract in the “From” column involved in a transaction listed above, then you are taken to the page below this text.
The page is your smart contract summary page. It tells you all the different transactions that have taken place involving this particular contract. The contract we clicked into does not have a name because the owner of the contract has not publicly claimed it or created an application around it. You can see from our list of “contract internal transactions” that the contracts underneath are named starting with Uniswap: V3. The only characteristic we know about this contract is its address which is the location on the blockchain where the smart contract code is stored.
Once you land on the contract page, you have the option to explore the contract on a more micro level by clicking on one of the following categories. (I will not define “Transactions” or “Internal transactions as we have already done that above.)
Contract (Link): The code that creates the functionality of a smart contract. It is where you can inspect the instructions within the smart contract to understand what it is doing. When a transaction occurs that involves communication with a smart contract, the code listed below executes whatever is coded. The code is stored on a blockchain and executes when a communication is sent to a smart contract.
Analytics (Link): Summarizes important information about a smart contract over time.
Comments (Link): Provide users a place to communicate with others about the smart contract. They can leave questions or make general statements.
The information that can be obtained from a block explorer is immense. Bitcoin’s lack of smart contracts makes it easier for someone interested in examining a blockchain to explore while Ethereum’s is more complicated because of the added functionality of smart contracts. Despite the complexity, blockchains hold all this information publicly thereby allowing anyone to interact with it and create different ways to visualize it. Blockchain.com and Etherscan.io are only two options. Txstreet.com provides a more enjoyable way to engage with the data.