├── Ethereum Explained.ipynb
├── README.md
├── app
├── index.html
├── javascripts
│ ├── app.js
│ ├── hooked-web3-provider.min.js
│ └── lightwallet.min.js
└── stylesheets
│ └── app.css
├── contracts
├── Conference.sol
└── Migrations.sol
├── migrations
├── 1_initial_migration.js
└── 2_deploy_contracts.js
├── test-genesis.json
├── test
└── conference.js
└── truffle.js
/Ethereum Explained.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "## Demo - We'll build a decentralized conference ticket purchasing web app\n",
8 | "\n",
9 | "## What is Ethereum?\n",
10 | "\n",
11 | "Ethereum is a platform to easily build decentralized applications (Đapps)\n",
12 | "using blockchain technology. \n",
13 | "\n",
14 | "\n",
15 | "\n",
16 | "## A decentralized what?\n",
17 | "\n",
18 | "\n",
19 | "\n",
20 | "A Dapp\n",
21 | "\n",
22 | "- Doesn't depend on any specific party existing. \n",
23 | "- Not for selling a specific party's service\n",
24 | "- Instead, a tool for people and organizations on different sides of an interaction used to come together without any centralized intermediary.\n",
25 | "\n",
26 | "## Dapp Examples built using Ethereum\n",
27 | "\n",
28 | "http://weifund.io/\n",
29 | "\n",
30 | "- Provides an open platform for crowdfunding campaigns that leverages smart contracts. \n",
31 | "- It enables contributions to be turned into contractually backed digital assets that can be used, traded or sold within the Ethereum ecosystem.\n",
32 | "\n",
33 | "https://www.augur.net/\n",
34 | "\n",
35 | "- An open-source prediction & forecasting market platform that allows anyone to forecast events and get rewarded for predicting them correctly \n",
36 | "- Predictions on future real world events\n",
37 | "- If a person buys shares in a winning prediction, they receive monetary rewards.\n",
38 | "\n",
39 | "https://www.provenance.org/\n",
40 | "\n",
41 | "- Using Ethereum to make opaque supply chains more transparent\n",
42 | "- By tracing the origins and histories of products, the project aims to build an open & accessible framework of information so consumers can make informed decisions when they buy products.\n",
43 | "\n",
44 | "## Let's get to the Architecture\n",
45 | "\n",
46 | "## The Stack\n",
47 | "\n",
48 | "\n",
49 | "\n",
50 | "\n",
51 | "\n",
52 | "### Overview \n",
53 | "\n",
54 | "\n",
55 | "\n",
56 | "### Let's talk Merkle Trees for a second\n",
57 | "\n",
58 | "- Merkle trees are a fundamental part of what makes blockchains tick. \n",
59 | "- Theoretically possible to make a blockchain without Merkle trees by creating giant block headers that directly contain every transaction\n",
60 | "- But Doing that poses large scalability challenges\n",
61 | "- Merkle trees make it possible to build Ethereum nodes that run on all sorts of computers\n",
62 | "- A way of hashing a large number of “chunks” of data together which relies on splitting the chunks into buckets, where each bucket contains only a few chunks, then taking the hash of each bucket and repeating the same process, continuing to do so until the total number of hashes remaining becomes only one: the root hash\n",
63 | "\n",
64 | "\n",
65 | "\n",
66 | "- Allows for Merkle Proofs\n",
67 | "- A Merkle proof consists of a chunk, the root hash of the tree, and the “branch” consisting of all of the hashes going up along the path from the chunk to the root\n",
68 | "- Someone reading the proof can verify that the hashing is consistent going all the way up the tree \n",
69 | "- Allows a mechanism for authenticating a small amount of data, like a hash, to be extended to also authenticate large databases of potentially unbounded size.\n",
70 | "\n",
71 | "The Bitcoin blockchain uses Merkle proofs in order to store the transactions in every block:\n",
72 | "\n",
73 | "\n",
74 | "\n",
75 | "The benefit that this provides is the concept that Satoshi described as “simplified payment verification”: instead of downloading every transaction and every block, a “light client” can only download the chain of block headers, 80-byte chunks of data for each block that contain only five things:\n",
76 | "\n",
77 | "- A hash of the previous header\n",
78 | "- A timestamp\n",
79 | "- A mining difficulty value\n",
80 | "- A proof of work nonce\n",
81 | "- A root hash for the Merkle tree containing the transactions for that block.\n",
82 | "\n",
83 | "It's limitation is that whileit can prove the inclusion of transactions, they cannot prove anything about the current state (eg. digital asset holdings, name registrations, the status of financial contracts, etc).\n",
84 | "\n",
85 | "So Every block header in Ethereum contains not just one Merkle tree, but three trees for three kinds of objects:\n",
86 | "\n",
87 | "- Transactions\n",
88 | "- Receipts (essentially, pieces of data showing the effect of each transaction)\n",
89 | "- State\n",
90 | "\n",
91 | "\n",
92 | "\n",
93 | "This allows clients to easily make and get verifiable answers to queries like\n",
94 | "\n",
95 | "- Tell me all instances of an event of type X (eg. a crowdfunding contract reaching its goal) emitted by this address in the past 30 days\n",
96 | "\n",
97 | "### The software libraries on GitHub\n",
98 | "\n",
99 | "Serverless stack\n",
100 | "- The Ethereum Virtual Machine is ‘calculate’ element that runs contract logic\n",
101 | "- Swarm is Peer-to-Peer file sharing, similar to BitTorrent, but incentivised with micropayments of ETH. \n",
102 | "- Whisper is an encrypted messaging protocol that allows nodes to send messages directly to each other in a secure way and that also hides the sender and receiver from third party snoopers.\n",
103 | "\n",
104 | "To run Ethereum, you can download (or write yourself if you have the patience) some software called an Ethereum client. Just like BitTorrent or Bitcoin, the Ethereum client will connect over the internet to other people’s computers running similar client software and start downloading the Ethereum blockchain from them to catch up. It will also independently validate that each block conforms to the Ethereum rules.\n",
105 | "\n",
106 | "You can use it to:\n",
107 | "\n",
108 | "- Connect to the Ethereum network\n",
109 | "- Explore Ethereum’s blockchain\n",
110 | "- Create new transactions and smart contracts\n",
111 | "- Run smart contracts\n",
112 | "- Mine for new blocks\n",
113 | "- Your computer becomes a ‘node’ on the network, running an Ethereum Virtual Machine, and behaves equivalently to all the other nodes. Remember in a peer-to-peer network there is no ‘master’ server and any computer has equivalent powers or status to any other.\n",
114 | "\n",
115 | "\n",
116 | "\n",
117 | "#### Ethereum clients\n",
118 | "\n",
119 | "- geth (written in a language called Go) https://github.com/ethereum/go-ethereum\n",
120 | "- eth (written in C++) https://github.com/ethereum/cpp-ethereum\n",
121 | "- pyethapp (written in Python) https://github.com/ethereum/pyethapp\n",
122 | "\n",
123 | "These are all command-line based programs (think green text on black backgrounds) and so additional software can be used for a nicer graphical interface. \n",
124 | "\n",
125 | "Currently the official and most popular graphical one is Mist (https://github.com/ethereum/mist), which runs on top of geth or eth.\n",
126 | "\n",
127 | "#### Smart Contract languages \n",
128 | "\n",
129 | "\n",
130 | "\n",
131 | "There are three common languages smart contracts are written in, which can be compiled into smart contracts and run on Ethereum Virtual Machines.\n",
132 | "\n",
133 | "- Solidity – similar to the language Javascript. This is currently the most popular and functional smart contract scripting language.\n",
134 | "- Serpent – similar to the language Python, and was popular in the early history of Ethereum.\n",
135 | "- LLL (Lisp Like Language) – similar to Lisp and was only really used in the very early days. It is probably the hardest to write in.\n"
136 | ]
137 | },
138 | {
139 | "cell_type": "markdown",
140 | "metadata": {},
141 | "source": [
142 | "# Workflow for Deploying Smart Contracts\n",
143 | "\n",
144 | "The workflow is:\n",
145 | " \n",
146 | "- Start an Ethereum node (e.g. geth or testrpc or ethersim)\n",
147 | "- Compile your Solidity smart contract using solc => get back the binary\n",
148 | "- Deploy your compiled contract to the network. (This step costs ether and signs the contract using your node’s default wallet address, or you can specify another address.) => get back the contract’s blockchain address and ABI (a JSON-ified representation of your compiled contract’s variables, events and methods that you can call)\n",
149 | "- Call stuff in the contract using web3.js’s JavaScript API to interact with it (This step may cost ether depending on the type of invocation.)\n",
150 | "\n",
151 | "\n",
152 | "\n",
153 | "- Model View Controller architecutre still applies in a Dapp.\n",
154 | "- your controller will speak to blockchains and DHTs instead of servers.\n",
155 | "- We need smart models, thin controllers, and dumb views. \n",
156 | "- certain elements that need consensus via smart contracts that would usually require a server (like usernames or financial actions)\n",
157 | "- Smart contracts are technically ‘models’ and you can feed data into them via transactions, but\n",
158 | "they are not the de facto ‘model’ in MVC architecture. They can work alongside your existing\n",
159 | "models but their utility on really applies in specific scenarios. These will come up on a case-by-\n",
160 | "case basis.\n",
161 | "\n"
162 | ]
163 | },
164 | {
165 | "cell_type": "markdown",
166 | "metadata": {},
167 | "source": [
168 | "# Lets Start Building! \n",
169 | "\n",
170 | "### Updates\n",
171 | "\n",
172 | "Current code uses *Truffle v2.0.4*\n",
173 | "\n",
174 | "\n",
175 | "### Install\n",
176 | "\n",
177 | "Install [testrpc] (or use geth)\n",
178 | "\n",
179 | "```\n",
180 | "$ npm install -g ethereumjs-testrpc\n",
181 | "```\n",
182 | "\n",
183 | "Install [truffle](https://github.com/consensys/truffle):\n",
184 | "\n",
185 | "```\n",
186 | "$ npm install -g truffle \n",
187 | "```\n",
188 | "\n",
189 | "If you don't have solc you can get it [here](https://github.com/ethereum/go-ethereum/wiki/Contract-Tutorial#using-an-online-compiler)\n",
190 | "\n",
191 | "### Run\n",
192 | "\n",
193 | "Run testrpc in one console window:\n",
194 | "\n",
195 | "```\n",
196 | "$ testrpc\n",
197 | "```\n",
198 | "In another console window run truffle from project root directory:\n",
199 | "\n",
200 | "```\n",
201 | "$ truffle compile\n",
202 | "$ truffle migrate\n",
203 | "$ truffle test\n",
204 | "$ truffle serve // server at localhost:8080\n",
205 | "```\n",
206 | "\n",
207 | "\n"
208 | ]
209 | },
210 | {
211 | "cell_type": "code",
212 | "execution_count": null,
213 | "metadata": {
214 | "collapsed": true
215 | },
216 | "outputs": [],
217 | "source": []
218 | }
219 | ],
220 | "metadata": {
221 | "kernelspec": {
222 | "display_name": "Python 3",
223 | "language": "python",
224 | "name": "python3"
225 | },
226 | "language_info": {
227 | "codemirror_mode": {
228 | "name": "ipython",
229 | "version": 3
230 | },
231 | "file_extension": ".py",
232 | "mimetype": "text/x-python",
233 | "name": "python",
234 | "nbconvert_exporter": "python",
235 | "pygments_lexer": "ipython3",
236 | "version": "3.6.0"
237 | }
238 | },
239 | "nbformat": 4,
240 | "nbformat_minor": 2
241 | }
242 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | ## Overview
3 |
4 | This is the code for video on Youtube by Siraj Raval on Ethereum. We'll build a simple Ethereum smart contract and lightwallet example. Any problems running the code? See the [issues
5 | ](https://github.com/Tigercoder0218/Ethereum_demo) section.
6 |
7 |
8 | ### Updates
9 |
10 | Current code uses *Truffle v2.0.4*
11 |
12 |
13 | ### Install
14 |
15 | Install [testrpc] (or use geth)
16 |
17 | ```
18 | $ npm install -g ethereumjs-testrpc
19 | ```
20 |
21 | Install [truffle](https://github.com/Tigercoder0218/Ethereum_demo):
22 |
23 | ```
24 | $ npm install -g truffle@2.0.4
25 | ```
26 |
27 | If you don't have solc you can get it [here](https://github.com/Tigercoder0218/Ethereum_demo)
28 |
29 | ### Run
30 |
31 | Run testrpc in one console window:
32 |
33 | ```
34 | $ testrpc
35 | ```
36 | In another console window run truffle from project root directory:
37 |
38 | ```
39 | $ truffle compile
40 | $ truffle migrate
41 | $ truffle test
42 | $ truffle serve // server at localhost:8080
43 | ```
44 |
45 |
46 | ## Credits
47 |
48 | Credits for this code go to [Tigercoder](https://github.com/Tigercoder0218/Ethereum_demo). I've merely created a wrapper to get people started.
49 |
50 |
--------------------------------------------------------------------------------
/app/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |