ETCPlanet.org: How To Create Your Own Ethereum Classic Blockchain Explorer For Learning (& Fun)

in etc •  8 years ago  (edited)

ETC

Ethereum Classic (ETC) blockchain explorers are convenient sources of information about the ETC blockchain. They may appear complex, but, it is relatively easy to build your own! Creating an ETC blockchain explorer is also a great learning exercise.

Requirements

checkmarks

ETC blockchain explorers require access to an ETC network node. These computers contain continually updated copies of the ETC blockchain. It is relatively easy to set up an ETC node with Parity. Blockchain information can be obtained from ETC Parity nodes with JavaScript Object Notation (JSON) commands. You will likely also want a web application framework to build a web interface.

Users should be able to at least request information about blocks, transactions and accounts. These can all be specified with hashes. Users should also be able to specify blocks with block numbers. There is no immediate way to determine if a 32 byte hash refers to a block or transaction. You may have to search for both a block and a transaction to see which leads to nonempty results.

Here is Python code that processes search requests, and sends JSON commands to a local ETC Parity node, to get the relevant blockchain information:

import urllib.request
import json

NODE_URL           = "http://127.0.0.1:8545"
N_TRANS_HASH_BYTES = 32

def do_json_rpc(method, args):
        """
        Does a JSON RPC command.
        """

        node_data = {"method"  : method,
                     "params"  : args,
                     "jsonrpc" : "2.0",
                     "id"      : 1}
        node_data = json.dumps(node_data).encode()
        node_post = urllib.request.Request(NODE_URL)
        node_post.add_header("Content-Type", "application/json")
        node_post = urllib.request.urlopen(node_post, node_data).read().decode()

        return json.loads(node_post)

def get_blockchain_info(search_text):
        """
        Gets blockchain info.
        """

        search_text = search_text.strip()
        if search_text.startswith("0x"):
                if len(search_text) == 2 * N_TRANS_HASH_BYTES + 2:
                        method = "eth_getTransactionByHash"
                        data   = do_json_rpc(method, [search_text])
                        if (not "result" in data) or (not data["result"]):
                                method = "eth_getBlockByHash"
                                args   = [search_text, "false"]
                                data   = do_json_rpc(method, args)
                else:
                        method  = "eth_getBalance"
                        data    = [do_json_rpc(method, [search_text])]
                        method  = "eth_getCode"
                        data   += [do_json_rpc(method, [search_text])]
        else:
                method = "eth_getBlockByNumber"
                data   = do_json_rpc(method, [search_text, "false"])
        try:
                if isinstance(data, list):
                        data = (search_text,
                                data[0]["result"],
                                data[1]["result"])
                else:
                        data = data["result"]
        except KeyError:
                method = None

        return (method, data)

ETCPlanet.org

planet

I created the ETCPlanet.org blockchain explorer using the Django web framework and Nginx web server. Search requests are relayed to a local ETC Parity node and the corresponding blockchain information is quickly displayed. Feel free to try it out and inspect the source code.

Conclusion

happy

Best of luck if you decide to attempt this project. If you need any assistance feel free to contact me. If you are successful, you might consider benefiting the ETC community by announcing your new resource on the ETC Reddit, adding it to the ETC bootstrap node list, and, adding it to the ETC network status monitor list.

Feedback

Feel free to leave any comments or questions below. You can also contact me by clicking any of these icons:

twitter facebook linkedin

Acknowledgements

I would like to thank IOHK (Input Output Hong Kong) for funding this effort.

License

license

This work is licensed under the Creative Commons Attribution ShareAlike 4.0 International License.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
  ·  8 years ago (edited)

ETC network status monitor link is http://etcstats.net/

Thanks! Fixed. Do you know why etcstats.net does not use at least a free letsencrypt cert to do SSL? Just curious.