Book Image

Ethereum Cookbook

By : Manoj P R
Book Image

Ethereum Cookbook

By: Manoj P R

Overview of this book

Ethereum and Blockchain will change the way software is built for business transactions. Most industries have been looking to leverage these new technologies to gain efficiencies and create new business models and opportunities. The Ethereum Cookbook covers various solutions such as setting up Ethereum, writing smart contracts, and creating tokens, among others. You’ll learn about the security vulnerabilities, along with other protocols of Ethereum. Once you have understood the basics, you’ll move on to exploring various design decisions and tips to make your application scalable and secure. In addition to this, you’ll work with various Ethereum packages such as Truffle, Web3, and Ganache. By the end of this book, you’ll have comprehensively grasped the Ethereum principles and ecosystem.
Table of Contents (13 chapters)

Using block explorer

There are many ways to read data from a transaction or a block in Ethereum. Etherscan is one block explorer and analytics platform for Ethereum. In this recipe, you will learn about the platform and how you can make use of it.

How to do it...

  1. Go to https://etherscan.io/ to access the block explorer. You will see a dashboard that displays the network state:
  1. On the top left, you can see a card that displays the current Ethereum market share along with the exchange rate. You can also see a transaction history chart for the last 14 days.
  2. Search for a block number or select it from the recent blocks list to view the contents of the block. You can see details such as time, miner, hash, transactions, size, gas, and so on:
  1. By searching a transaction, you can view transaction details such as from address, to address, the value transferred, gas, and other details.
  2. Etherscan also offers a details page for both Externally Owned Addresses (EOA) and contract addresses. To see the balance, list of transactions, and even tokens owned by that address, navigate to the EOA details page.
  3. The contract page also shows the balance, transactions, and even a contract code if it is a verified contract. To interact with verified contracts through Etherscan, use this page.
  4. The platform also offers charts for analytics. Use the charts to get an idea about the currency, network, mining, blocks, transactions, and other general information.
  5. Click the MISC tab to use tools such as the mining calculator, bytecode converter, and transaction broadcaster.
  6. Etherscan also has a free to use API for reading data from Ethereum. Sign up to Etherscan to use the API and use the free API key that can be generated from the portal itself. Make sure that you are not making more than five requests per second. You will be blocked if this is exceeded.
  1. Signing up with Etherscan will allow you to watch specific addresses and create email alerts. You can even add a private note for each transaction.

There's more...

Eth-netstats is a visual interface for tracking an Ethereum network status. To access the public status page, go to https://ethstats.net/. Note that the portal does not represent the entire state of the Ethereum main net. This is because of the voluntary listing of nodes in the portal.

You can use netstats to visualize your private Ethereum network:

  1. Download the source code from the repository. Make sure to verify the license:
git clone https://github.com/cubedro/eth-netstats
  1. Install the dependencies:
sudo npm install -g grunt-cli
cd eth-netstats
npm install
  1. Build the project using grunt and use npm to run it:
grunt
npm start