HomeЛюди и блогиRelated VideosMore From: Blockgeeks

How to Build an Ethereum Blockchain Explorer Dapp

112 ratings | 8054 views
How to Build an Ethereum Blockchain Explorer Dapp - https://blockgeeks.com/ In this lesson we’re going to see how to build a simple dapp using the Ethereum blockchain as our backend We’re going to build a blockchain explorer, kind of like etherscan, but we’re only going to display the last 10 blocks on the chain. To do this, we’ll use an open-source framework called Ethers.io to quickly develop and deploy our dapp. Ethers comes with command line tools which are available as a node module and can be installed using npm install -g ethers-cli. Let’s install to our global context since we’ll probably use this across multiple projects. You can read more about Ethers by checking out their awesome documentation online. Ethers.io makes it easy to create dapps by allowing you to quickly run them locally during development. One of the things I really like is that it removes the need to have a copy of the blockchain, so we don’t need to run a local geth node for example in order to build dapps. Another thing I really like is that it comes with a free hosting service called ethers.space, where we can store some of our static files for free. We’ll see how to use this later, but for now we’ll just keep everything local. The first step is to create a new project folder for our dapp and navigate into it. We’ll call our project, explorer. To use the ethers.space hosting, we need to have an Ethereum account and we can create one by calling ethers-build init, which generates a keyfile for us called account.json. Make sure you use a strong password when encrypting your private key. Your keyfiles never leave your web browser’s local storage when using Ethers Now let’s start by building our front-end UI. We can create a new HTML file called index.html and define a head and body for our document. Let’s put hello world in the body, and we’ll also give our page a title. We can quickly spin up a local web server to serve this index.html by using the command ethers-build serve. By default, Ethers will point to the mainnet, but we can also pass the —testnet option to point to ropsten. This prints out a local http address where we can see our UI. Let’s paste this URL into a browser. We get some sort of view rendered, but this isn’t like anything we wrote in our HTML. We keep seeing this ‘loading application’ spinner because we haven’t included the ethers-app javascript in our document. Let’s add a script tag to the end of our body and link it to the minified ethers-app javascript. Now when we reload the page in the browser, we are at least able to see our Hello World message meaning our application is loading. There’s also a dashboard across the top of the page, but we didn’t actually write any of this in our index.html. This view is inserted by the Ethers.io container running locally. Through the Ethers.io container, we can serve multiple apps by passing the application URL at the end of the fragment. The part after the hashtag tells the Ethers.io container which application to load. Typically we would have to run the Ethers.io container over https, but it allows for running over http for development. The Ethers.io container provides a bunch of other tools for us like a messenger, a testnet faucet and even its own blockchain explorer, but we won’t get into these features right now. Let’s try displaying the last 10 blocks from the blockchain in our UI. We can replace our hello world text with an HTML table element that defines 3 column headers. We’ll print out each block’s number, hash and timestamp of creation. Let’s give our table an ID so we can reference it later in javascript and we’ll also set the width to 100% To read more, visit https://blockgeeks.com/
Html code for embedding videos on your blog
Text Comments (6)
bhagya panda (3 months ago)
How to build block explorer make full video on it I'm your subscriber
Deepak shinde (8 months ago)
Good
lexfaraday (11 months ago)
This is not How to build an Ethereum Blockchain Explorer Dapp, this is a "How to consume the etherscan.io API".
Mushtaq Bhat (1 year ago)
Great job Blockgeeks and many thanks for keeping us updated! Happy to have subscribed to your newsletter. Informative, infectiously enthusiastic and a fun to read beside. THANKS!
One comment, for anyone else really starting from scratch on a pretty bare Windows 10 machine, npm install ethers-cli will fail, with: "MSBUILD : error MSB3428: Could not load the Visual C++ component "VCBuild.exe". To fix this, 1) install the .NET Framework 2.0 SDK, 2) install Microsoft Visual Studio 2005 or 3) add the location of the component to the system path if it is installed elsewhere." To actually fix this, see the instructions here: https://github.com/nodejs/node-gyp
Mickey San Miguel (1 year ago)
As always, THANK YOU! Much to learn and lots of fun to be had 🙂

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.