Skip to content

A blockchain explorer written in Go to learn about building server-side applications that work with the Ethereum blockchain.

License

Notifications You must be signed in to change notification settings

curvegrid/toy-block-explorer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

toy-block-explorer

A blockchain explorer written in Go to learn about building server-side applications that work with the Ethereum blockchain.

Toy Block Explorer

Pre-requisites

You will need to install the following to build and work with this project:

  • Go (also called 'golang') a programming language. Advanced macOS users will probably want to install via Homebrew.
  • Git, a package management system. For macOS users, we again recommend Homebrew. For Windows users, at this point it would be prudent to install Cygwin, which gives you access to many Unix commands, including Git. You will need to ensure that Git is selected during the Cygwin installation process.
  • Geth, the official Ethereum node and command line interface (CLI) tool.
  • This repository and its submodules, which you can install by running:
$ git clone https://github.com/curvegrid/toy-block-explorer.git
$ cd toy-block-explorer
$ git submodule init
$ git submodule update --recursive

Optional components and setup steps include:

  • The go-ethereum libraries are also a pre-requisite, but the included build.sh command will run the required go get command to pull these in for you.
  • abigen and solc are required if you wish to regenerate the erc20.go file from its ERC20Interface.sol source.

How to use this tutorial

This tutorial is broken down into several stages, separated by git branches. The default master branch contains a bare bones web application. Subsequent intermediate branches, step-1, step-2, etc. contain more and more of the block explorer functionality filled in. The complete explorer is in the branch step-final.

The idea is for you to start will the bare bones web application, and build the complete block explorer yourself. If you get stuck, you can always skip ahead of examine the next step's branch for hints or help. Of course, it's up to you, so feel free to start with step-final and work backwards!

You can checkout a specific branch with:

$ git checkout -b step-N

Learn more about working with Git here.

Setting up a local blockchain node for testing purposes

We use the full Geth Ethereum node running in a development mode, since it most closely mimics the operation of a production blockchain node. We've included the Easy Geth Dev Mode set of scripts as a submodule, along with a sample chaindata folder pre-populated with a few transactions, to get you started.

First, ensure the Easy Geth Dev Mode submodule was pulled in correctly:

$ git submodule init
$ git submodule update --recursive

Copy the sample chaindata folder into the submodule:

$ cp -R geth/sample-chaindata geth/easy-geth-dev-mode/chaindata

Run Geth:

$ cd geth/easy-geth-dev-mode
$ ./launch43.sh --ipcdisable --startrpc

A local version of Geth is now running with a JSON RPC endpoint exposed at http://localhost:8545

If you receive an error, geth may still be running. You can check this with:

ps -ef | grep geth

If you still have trouble running geth in this manner, try ./stop43.sh and then ./launch43.sh --ipcdisable --startrpc a few times. You can also try:

geth --dev --datadir ./chaindata --rpc console

You may need to manually send some transactions. For example:

eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(300, "ether")})

Once you're finished with Geth, be sure to stop it:

$ ./stop43.sh

Building and running the project

Run the build script:

$ ./build.sh

This will generate a toy-block-explorer executable:

$ ./toy-block-explorer 
2018/06/08 15:02:50 Connecting to Ethereum node at http://localhost:8545
2018/06/08 15:02:50 Web server started on :8080

Try browsing to http://localhost:8080

The toy block explorer has a number of command line options:

$ ./toy-block-explorer -h
Usage of ./toy-block-explorer:
  -ethendpoint string
    	Ethereum node endpoint (default "http://localhost:8545")
  -host string
    	Hostname to bind web server to
  -port int
    	Port to bind web server to (default 8080)
  -templates string
    	Templates glob (default "templates/*")
  -www string
    	Directory to serve (default "www")

If you want to connect it to the Ethereum mainnet, sign up for an Infura account and have the block explorer connect to it instead of your local Geth dev node:

$ ./toy-block-explorer -ethendpoint https://mainnet.infura.io/<API key here>

Licence

MIT

Copyright and credits

Go source files copyright (c) 2018 Curvegrid Inc.

Portions of the HTML based on Bootstrap's samples.

ERC20 Solidity interface based on The Ethereum Wiki's ERC20 Standard page.

About

A blockchain explorer written in Go to learn about building server-side applications that work with the Ethereum blockchain.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published