Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Blockchain, Ethereum, Smart Contracts, and Tokens

221 views

Published on

An introduction to newbies. What is a blockchain and why to use it? Ethereum technology vs Bitcoin technology. Smart contracts. Solidity programming. An example smart contract.

Published in: Software
  • Be the first to like this

Blockchain, Ethereum, Smart Contracts, and Tokens

  1. 1. BLOCKCHAIN, ETHEREUM, SMART CONTRACTS, TOKENS Dr. Yoram Kornatzky kornatzky@gmail.co m http://yoramkornatzky.com
  2. 2. Bank The Banking System Accounts Ledger Transaction Consumer: Joe Contractor: Julia
  3. 3. Money Transfer Paris Bank Frankfurt Bank Swift Sophie Johannes Transaction Transaction
  4. 4. BLOCKCHAIN • A decentralised ledger - distributed across many computers • No central server - bank • Collection of computers - peers • Each holding the ledger • Consensus among computers • P2P
  5. 5. The Network - P2P
  6. 6. Blockchain 1003 4 2 1 0… Tx1 Tx4 Tx2 Tx3
  7. 7. THE INCENTIVE • Payment • Ether / Bitcoin • Accounts
  8. 8. ETHEREUM • Blockchain • Each node runs an Ethereum Virtual Machine (EVM) • Solidity Programming Language • Turing Complete
  9. 9. GETH - ETHEREUM GO CLIENT brew install geth # get the file genesis.json geth - - datadir=~/datadir init genesis.json geth - - datadir=~/datadir account new # will request password
  10. 10. GETH - JAVASCRIPT CONSOLE geth - - datadir=~/datadir
  11. 11. > eth.accounts ["0xb91b6b1840ed6850ddedc67564b2049f51e53baa", “0x13114f57a2240c4d870d95a8ab1ad3c0dacca26a"] > eth.getBalance("abcxyz") Error: invalid address at web3.js:3930:15 at web3.js:5025:28 at map (<native code>) at web3.js:5024:12 at web3.js:5050:18 at web3.js:5075:23 at <anonymous>:1:1 > eth.getBalance("0xb91b6b1840ed6850ddedc67564b2049f51e53baa") 2.4179e+22
  12. 12. > web3.fromWei(eth.getBalance(eth.accounts[0]), "ether") 24179 > eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(3, "ether")}) Error: authentication needed: password or unlock at web3.js:3143:20 at web3.js:6347:15 at web3.js:5081:36 at <anonymous>:1:1 > personal.unlockAccount(eth.accounts[0], "secret") true
  13. 13. > eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(3, "ether")}) INFO [01-27|13:58:06] Submitted transaction fullhash=0x6c6226f6bf411cc9a1ccc2071127482d6b62eb1b300e 83209f72d5bfa105c536 recipient=0x13114F57a2240C4D870d95A8AB1ad3C0daCCa26 A “0x6c6226f6bf411cc9a1ccc2071127482d6b62eb1b300e83209f7 2d5bfa105c536"
  14. 14. SMART CONTRACT • Executed on all nodes • Costs Ether - gas • Solidity programming language
  15. 15. MINIMAL TOKEN CONTRACT pragma solidity ^0.4.0; contract MinimalToken { mapping (address => uint256) public balanceOf; }
  16. 16. function MinimalToken(uint256 initialSupply) public { balanceOf[msg.sender] = initialSupply; } function transfer(address _to, uint256 _value) public{ require(balanceOf[msg.sender] >= _value); require(balanceOf[_to] + _value >= balanceOf[_to]); balanceOf[msg.sender] -= _value; balanceOf[_to] += _value; }

×