BLOCKCHAIN AND SMART
CONTRACTS
Introduction for Software
Developers and Architects
WHY BLOCKCHAIN IS A BIG DEAL
“Bitcoin is a technological tour de force.” – Bill Gates
”I think the fact that within the bitcoin universe an algorithm replaces
the function of the government …[that] is actually pretty cool.” - Al
Gore
“[Bitcoin] is a remarkable cryptographic achievement… The ability to
create something which is not duplicable in the digital world has
enormous value…Lot’s of people will build businesses on top of that.”
- Eric Schmidt
BLOCKCHAIN IS
Ledger of facts
Ledger of facts replicated across large number of
computers
Ledger of facts replicated across large number of
computers connected as peer-to-peer network
Ledger of facts replicated across large number of
computers connected as peer-to-peer network that
implements consensus algorithm that can securely
identify sender and receiver of facts
FACTS
Monetary
transaction
Content
hash
Signature
Asset
information
Ownership
Agreement
Contract
IS IT JUST ANOTHER SHARED
DATABASE?
NOT JUST ANOTHER DATABASE
Multiple Writers
Non-trusting
writers
Disintermediation
Interaction
between
transactions
Conflict
resolution
HOW?
Blocks
Decentralized consensus
Byzantine fault tolerance.
CHAIN OF TRANSACTIONS
TIMESTAMPS
RECORDING TRANSACTION
SMART
CONTRACTS
Introduction to Smart Contracts
EXAMPLE OF A CONTRACT
EXAMPLE OF SMART CONTRACT
SMART CONTRACT USE CASES
ICO
Digital
Identity
Public
records
Securities
International
trade
Derivatives
Mortgages Land title Supply chain
HANDS-ON
INTRODUCTION
TO SMART
CONTRACTS
With Etherium and Solidity
DEVELOPING SMART CONTRACT
WITH TRUFFLE
Write Code
Create
deployment
script
Migrate/Deploy
PREREQUISITES
•$ sudo npm install -g truffle
•$ mkdir solidity-experiments
•$ cd solidity-experiments/
•$ truffle init
Truffle
Framework
•$ sudo npm install -g ethereumjs-testrpc
•$ testrpc &
Etherium
test network
•module.exports = {
• networks: {
• development: {
• host: "localhost",
• port: 8545,
• network_id: "*" // Match any network id
• }
• }
•}
Configure
truffle.js
HELLO WORLD CONTRACT
(SOLIDITY CODE)
pragma solidity ^0.4.4;
contract Hello {
function Hello() public {
// constructor
}
function sayHello() public pure returns
(string) {
//console.log("sayHello() function
called...");
return 'Hello World!';
}
}
DEPLOYMENT SCRIPT
var Hello1 =
artifacts.require("./Hello.sol");
module.exports =
function(deployer) {
deployer.deploy(Hello1);
};
CONTRACT DEPLOYMENT
$ truffle console
truffle(development)> truffle migrate --reset
Using network 'development'.
Running migration: 1_initial_migration.js
Deploying Migrations...
...
0xb6bbeaaf3649ecb38d548cba96f681682dad9e0225726924fbee3ce3
6eff94e3
Migrations: 0xc08c46796ba0edc0bebbbd0d90868c010055cb0e
Saving successful migration to network...
...
0x16fe364b9f2c3e8f07fa1ebd6b84b8ad9b4e750d8698a7e920d824eb
d019dd80
Saving artifacts...
Running migration: 2_deploy_contracts.js
Deploying Hello...
...
0xfe120836b2d7395bd988104feff018fe352f93555f71003bbf1a6467
1cca9ba1
Hello: 0x2b649a87d20ce1ac3b6a0218e911165fa0f095f0
Saving successful migration to network...
...
0x1a09073a3b3f7996f3d63a81a99d8cd09198ad7b467f35f7ddc500a
4291332b9
Saving artifacts...
truffle(development)>
CONTRACT TEST
truffle(development)> var he =
Hello.at(Hello.address)
Undefined
truffle(development)> he.sayHello()
'Hello World!'
STAY IN TOUCH
Gene Leybzon https://www.linkedin.com/in/leybzon/
https://www.meetup.com/members/90744
20/
https://www.Leybzon.com
ANNOUNCEM
ENTS
Blockchain and Crypto
"Unconference" this Sunday 1/28
from 3-5PM in room Z301 at the
GSB Stanford

Blockchain and Smart Contracts

  • 1.
    BLOCKCHAIN AND SMART CONTRACTS Introductionfor Software Developers and Architects
  • 2.
    WHY BLOCKCHAIN ISA BIG DEAL “Bitcoin is a technological tour de force.” – Bill Gates ”I think the fact that within the bitcoin universe an algorithm replaces the function of the government …[that] is actually pretty cool.” - Al Gore “[Bitcoin] is a remarkable cryptographic achievement… The ability to create something which is not duplicable in the digital world has enormous value…Lot’s of people will build businesses on top of that.” - Eric Schmidt
  • 3.
    BLOCKCHAIN IS Ledger offacts Ledger of facts replicated across large number of computers Ledger of facts replicated across large number of computers connected as peer-to-peer network Ledger of facts replicated across large number of computers connected as peer-to-peer network that implements consensus algorithm that can securely identify sender and receiver of facts FACTS Monetary transaction Content hash Signature Asset information Ownership Agreement Contract
  • 4.
    IS IT JUSTANOTHER SHARED DATABASE?
  • 5.
    NOT JUST ANOTHERDATABASE Multiple Writers Non-trusting writers Disintermediation Interaction between transactions Conflict resolution
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
    EXAMPLE OF ACONTRACT
  • 12.
  • 13.
    SMART CONTRACT USECASES ICO Digital Identity Public records Securities International trade Derivatives Mortgages Land title Supply chain
  • 14.
  • 15.
    DEVELOPING SMART CONTRACT WITHTRUFFLE Write Code Create deployment script Migrate/Deploy
  • 16.
    PREREQUISITES •$ sudo npminstall -g truffle •$ mkdir solidity-experiments •$ cd solidity-experiments/ •$ truffle init Truffle Framework •$ sudo npm install -g ethereumjs-testrpc •$ testrpc & Etherium test network •module.exports = { • networks: { • development: { • host: "localhost", • port: 8545, • network_id: "*" // Match any network id • } • } •} Configure truffle.js
  • 17.
    HELLO WORLD CONTRACT (SOLIDITYCODE) pragma solidity ^0.4.4; contract Hello { function Hello() public { // constructor } function sayHello() public pure returns (string) { //console.log("sayHello() function called..."); return 'Hello World!'; } }
  • 18.
    DEPLOYMENT SCRIPT var Hello1= artifacts.require("./Hello.sol"); module.exports = function(deployer) { deployer.deploy(Hello1); };
  • 19.
    CONTRACT DEPLOYMENT $ truffleconsole truffle(development)> truffle migrate --reset Using network 'development'. Running migration: 1_initial_migration.js Deploying Migrations... ... 0xb6bbeaaf3649ecb38d548cba96f681682dad9e0225726924fbee3ce3 6eff94e3 Migrations: 0xc08c46796ba0edc0bebbbd0d90868c010055cb0e Saving successful migration to network... ... 0x16fe364b9f2c3e8f07fa1ebd6b84b8ad9b4e750d8698a7e920d824eb d019dd80 Saving artifacts... Running migration: 2_deploy_contracts.js Deploying Hello... ... 0xfe120836b2d7395bd988104feff018fe352f93555f71003bbf1a6467 1cca9ba1 Hello: 0x2b649a87d20ce1ac3b6a0218e911165fa0f095f0 Saving successful migration to network... ... 0x1a09073a3b3f7996f3d63a81a99d8cd09198ad7b467f35f7ddc500a 4291332b9 Saving artifacts... truffle(development)>
  • 20.
    CONTRACT TEST truffle(development)> varhe = Hello.at(Hello.address) Undefined truffle(development)> he.sayHello() 'Hello World!'
  • 21.
    STAY IN TOUCH GeneLeybzon https://www.linkedin.com/in/leybzon/ https://www.meetup.com/members/90744 20/ https://www.Leybzon.com
  • 22.
    ANNOUNCEM ENTS Blockchain and Crypto "Unconference"this Sunday 1/28 from 3-5PM in room Z301 at the GSB Stanford

Editor's Notes

  • #10 Image from http://techatlast.com/wp-content/uploads/2017/08/How-blockchain-technology-works.png
  • #12 Image from https://commons.wikimedia.org/wiki/File:Smart_contracts_in_insurance_policies.png
  • #18 http://leybzon.blogspot.com/2018/01/hello-world-from-solidity.html
  • #19 http://leybzon.blogspot.com/2018/01/hello-world-from-solidity.html
  • #20 http://leybzon.blogspot.com/2018/01/hello-world-from-solidity.html
  • #21 http://leybzon.blogspot.com/2018/01/hello-world-from-solidity.html