1 of 38

How to Build a DApp with Ethereum and Meteor JS

Bryan Gmyrek, Ph.D.

Blockchain Meetup

June 2016

meetup.com/blockchaintech

2 of 38

This talk is being recorded for the Blockchain Meetup public YouTube channel.

Please note and save your questions and comments.

We can discuss them at the end.

This will make editing much easier. Thanks!

Be forewarned: I blab a lot, get sidetracked easily,

and probably won’t impress you if you’re an Ethereum expert.

Any interweb trolls watching can save some time and just click away now.

You’ve been warned.

Blockchain Meetup YouTube Channel link:

https://goo.gl/GUIfpg

3 of 38

Speaker Introduction

B.S. from UMass Amherst, an M.A. from Boston University, and a Ph.D. (all in physics) from the University of Arizona with a focus on analysis of particle physics data from the Fermilab Tevatron in Batavia, IL using C++ on Linux. ( Proof: http://ccd.fnal.gov/techpubs/fermilab-reports-thesis.html )

Software developer part-time for 20 years, full time for 10, and have been a Bitcoin and “Distributed Technologies” enthusiast since about 2013. Participated in four Bitcoin Hackathons.

Interested in Ethereum since the Texas Bitcoin Conference in the Spring of 2014, started mining in 2015, and have given two talks on Ethereum so far this year ( https://goo.gl/A2fuvF ).

4 of 38

Previous Ethereum Talks

These talks were all presented this year at the Blockchain Meetup and can provide helpful background info for this talk and alternate/complimentary methods.

Hands On with Ethereum - Smart Contracts, Mining and More (Gmyrek)

https://www.youtube.com/watch?v=Bg-0JAmGUhQ

Hands On with Ethereum - How to Use the Mix IDE to Develop a DApp (Gmyrek)

https://www.youtube.com/watch?v=MJIF1YTOdDY

Creating a Cryptocurrency on Ethereum - Mahesh Balan

https://www.youtube.com/watch?v=NY5YusQdY3M

5 of 38

Some key concepts and underlying technologies.

We’re not going to discuss these much (this would take too much time)

Peer-to-Peer, Cryptography, Cryptocurrency, Blockchain, Mining

https://github.com/ethereum/wiki/wiki/Glossary

But let’s talk about these a little on the following slides

Smart Contracts

Ethereum Virtual Machine

DApp

6 of 38

Smart contract

https://github.com/ethereum/wiki/wiki/White-Paper

Smart contracts, cryptographic "boxes" that contain value and only unlock it if certain conditions are met, can also be built on top of the platform, with vastly more power than that offered by Bitcoin scripting because of the added powers of Turing-completeness, value-awareness, blockchain-awareness and state.

More info on the Bitcoin wiki https://en.bitcoin.it/wiki/Contract

Nick Szabo - 1997 (!!!) http://szabo.best.vwh.net/smart_contracts_idea.html

(These are the parts of your code that will run ‘inside the Ethereum blockchain’)

7 of 38

Ethereum Virtual Machine

https://dappsforbeginners.wordpress.com/tutorials/introduction-to-development-on-ethereum/

“The Ethereum Virtual Machine is the primary innovation of the Ethereum project. This is a virtual machine designed to be run by all participants in a peer to peer network, it can read and write to a blockchain both executable code and data, Verify digital signatures, and is able to run code in a quasi-Turing complete manner. It will only execute code when it receives a message verified by a digital signature, and the information stored on the blockchain tells it is appropriate to do so.”

(The EVM is what allows advanced smart contracts to be run)

8 of 38

DApp

https://dappsforbeginners.wordpress.com/tutorials/your-first-dapp/

“Ethereum enables the decentralised web, referred to as ‘web 3’....A Dapp (‘decentralized app’) consists of two parts: a frontend, written in HTML, and a backend (think of it as the ‘database’ for your frontend).”

Typically, a DApp is an app which runs in the user’s browser (using JavaScript) in a way which is nearly identical to how most modern web apps work. The difference is that select data can be read from and written to the Ethereum blockchain, and select code can also run in the Blockchain. -BDG

9 of 38

Steps to get started with Meteor DApps

Make sure Meteor is right for you

Install Meteor DApp Boilerplate

Create a private chain for testing

Start mining on the private chain

Start meteor

Examine contract files

Try running tests

Change some info on the app

Test out the example smart contract

10 of 38

11 of 38

Meteor DApp Boilerplate

12 of 38

13 of 38

Setting up an isolated private chain

# http://adeduke.com/2015/08/how-to-create-a-private-ethereum-chain/

cd; mkdir .gethTestDir

cd ~/Programs/ethereum/meteor-dapp-boilerplate/app

geth -dev --rpc --rpcaddr="0.0.0.0" --rpccorsdomain "*" --verbosity 5 --maxpeers 0 --genesis test-genesis.json --networkid 1234 --nodiscover --datadir $HOME/.gethTestDir console

# exit geth with Ctrl-C

14 of 38

Preparing the private chain

15 of 38

Cleaning up data on private chain before ‘mining’

16 of 38

Create newAccount for private chain

17 of 38

Modify boilerplate ‘test-genesis.json’

In Ethereum, you can choose what to put in the genesis block using a json file.

The ‘boilerplate’ app comes with a test-genesis.json We’ll add the account we just created.

18 of 38

Unlock and start ‘mining’ private chain

cd $HOME/.gethTestDir

geth -dev --rpc --rpcaddr="0.0.0.0" --rpccorsdomain "*" --minerthreads "1" --mine --verbosity 5 --maxpeers 0 --genesis test-genesis.json --networkid 1234 --nodiscover --datadir $HOME/.gethTestDir --unlock 0 --minerthreads "1" --mine

If you followed the previous instructions, the password should be badpassword.

19 of 38

Starting geth and ‘mining’

20 of 38

Even private chain mining takes work

21 of 38

Geth logs showing continuous mining

22 of 38

Time to start the meteor app locally

23 of 38

What did we get with the ‘Boilerplate’?

24 of 38

The (simple) example contract

In addition to the standard meteor folders and files, there’s a ‘contracts’ folder and a very simple example contract. More on this later.

25 of 38

The Meteor DApp Page - Port 3000

26 of 38

What’s mocha?

27 of 38

Using mocha to test Ethereum connectivity and Solidity smart contracts

meteor-dapp-boilerplate/app/tests/mocha/client/MultiplyContract.js

28 of 38

This is really cool.

29 of 38

Let’s change the DApp title.

30 of 38

31 of 38

32 of 38

Wait for the app to restart and … success

33 of 38

Try ‘view2’ - Create a New Contract

34 of 38

Verbose geth output is verbose

35 of 38

Trying out the deployed contract

36 of 38

37 of 38

Summary

We covered how to set up and use Meteor and geth to develop DApps locally.

Obviously there’s a lot more to making a production DApp (for example: useful smart contracts, deploying to the production blockchain, dealing with data in smart contracts, distributing your app’s code to users, etc)

Hopefully you have a taste of the potential benefits of using Meteor.

38 of 38

The End.

Questions / Discussion?