We are happy to invite you all to participate in the lecture, which our blockchain specialists are going to present on at SoftUni.
On that lecture we’ll explain fundamentals of blockchain technology, real live examples and upcoming challenges for the future applications of that new and beneficial technology.
Our team will present also the Open Source University project, how it will reshape the future of education, enhancing the connection between businesses and learning content providers. (www.os.university)
6. Bitcoin: Currency and technology
Bitcoin is the first decentralized digital currency.
“Satoshi Nakamoto”
2009
Mining
21 milion
Volatile value
> 50% in hands of 880
individuals
Litecoin, Ripple, Zerocoin
Blockchain
Distributed shared ledger
Cryptography (SHA-256, PKI)
Consensus model
Smart contracts
14. Key concepts of blockchain - Distributed ledgers
- Group of replicated nodes
- Transactions distributed in blocks
- Parties identified with public key
- Accessibility of transactions depending on blockchain implementation
- Resilient for failure of one or more nodes
- Group of nodes operate tamper proof
15. Key concepts of blockchain - Cryptography
Hashing
Creation of a bit string (digest) representing integrity of content other string. Changing one character in
the original string results in complete different hash. Changing multiple characters in original string
that results in the same hash requires large amount of processing power for a long
period of time.
Input data
Input data
Example how SHA-256
works
Example how SHA-256
works.
79e8a584005254f7717547b
5829fd01fa
c19617618972f1dc643b2bb
7075c7cac
Hashing Hashing
Extra dot
16. Key concepts of blockchain - Cryptography
Public & private keys and wallets
Two large prime numbers that have a mathematical relation with each other. A string encrypted with one key can only be decrypted with the
other. One needs to be kept private, the other one can be made publicly known so that it can be used
by other parties to exchange data with you in a secure manner.
Encryption
Scrambling of clear text with the public key of the recipient so that the holder of that private key is the only one that can descramble the
message guarantee the confidentiality of the data exchanged.
a66b311c9b158c1e55d4e6cc5
55016d2e554ac....
Confidential text
encryption decription
Confidential text
Public key Private key
PKI management
Digital signature
2626043be7d913ff5d8520b39253eef6240e
31d…
2100f86450888dc01725
af78a0e70415…
encryption decription
2100f86450888dc01725
af78a0e70415…
Private key Public key
PKI managementHash of data to be secured
Hash to be checked with
the original
17. Key concepts of blockchain - Consensus
4 main methods of finding consensus in the blockchain:
- byzantine fault tolerance algorithm (PBFT)
- proof-of-work algorithm(PoW)
- proof-of-stake algorithm (PoS)
- delegated proof-of-stake algorithm (DPoS)
19. Key concepts of blockchain -
Smart Contract
Business logic that can be assigned to
a transaction on the blockchain
Acts as a ‘notary’ of blockchain
transactions
Holds conditions under which specific
actions can/must be performed
Can’t be modified without predefined
permissions
20. ● Data of the transaction is the compiled contract
● Contracts can call other contracts (they can even call themselves)
● High level languages (for which compilers exist)
- Solidity (Javascript like)
- Serpent (Python like)
- LLL (Lisp like)
● Everything you use in a smart contract is publicly visible
Key concepts of blockchain - Smart Contract
21. 1. Setting up a project with Truffle
Getting ready to write Smart Contract
Initialize Truffle Project
Contract Skeleton
Deploy / Migrate
22. Getting ready to write Smart Contract - initialize
Truffle project
● Create directory for the project
> truffle init
● Create new contract skeleton
> truffle create contract Calculator
23. Getting ready to write Smart Contract - initialize
Truffle project
● Add the contract to migrations/deploy_contracts.js
● Run TestRPC
● Deploy contract to TestRPC
Deploy / Migrate
> truffle migrate
24. Truffle & TestRPC - Coding smart contracts
Specifications Code contract Compile contract
Add Test Cases Test contract TestRPC
25. Truffle & TestRPC - Coding smart contracts
● Calculator contract
State = Number
State will change by operations:
- addToNumber(uint x)
- subtractFromNumber(uint x)
- multiplyWithNumber(uint x)
- divideNumberBy(uint x)
- getResult() returns current value
Specifications
26. Truffle & TestRPC - Coding smart contracts
● Test #1 Calculator should have result initialized to 10
● Test #2 Adding 10 & subtracting 5 should lead to result =
15
Add Test Cases
> truffle create test Calculator
27. Truffle & TestRPC - Coding smart contracts
● Test #1 Calculator should have result initialized to 10
Add Test Cases
28. Truffle & TestRPC - Coding smart contracts
● Test #2 Adding 10 & subtracting 5 should lead to result =
15
Add Test Cases
29. Truffle & TestRPC -
Coding smart contracts
● Code the contract
● Code the functions
- addToNumber(uint x)
- subtractFromNumber(uint x)
- multiplyWithNumber(uint x)
- divideNumberBy(uint x)
- getResult() returns current value
Code contract
30. ● Compilation is done by Truffle framework
> truffle compile
● Change in deployment configuration - Redeploy contract
> truffle migrate
● Test smart contract
> truffle test
OR
> truffle <specific script>
Compile contract
C:ProgramsicoCalculator>truffle migrate
Running migration: 1_initial_migration.js
Deploying Migrations...
... 0x18ebd894d886dc4c6bfb286990efe682aa57a6a9c15b817c8b8d949db980ab2f
Migrations: 0xc8fa60795442def0b8df0a79e51e8d42714e84bd
Saving successful migration to network...
... 0xeb8cc164b73e4e6999c8868d7a21b0aa1cd39cb524ff25037a339135eb620174
Saving artifacts...
Running migration: 2_deploy_contracts.js
Deploying Calculator...
... 0x0fc6de85ea4cf7aa143b015204b0b547e2f51989cecdfa5fc085b9ec6a3f6824
Calculator: 0xbff49106559d670bd71e868ba7d2caab2aaef734
Saving successful migration to network...
... 0x463494b042367e8ea9396e4a43fd2815929016a46b6d27c0ac4c0da050bcce90
Saving artifacts...
Test contract&
Truffle & TestRPC - Coding smart contracts
32. Now we have a way to create
complex transactions between
untrusted individuals
33. Ethereum Virtual Machine (EVM)
Ethereum VM handles internal state
and computation.
- States are stored on distributed
global ledger
- Computation is paid for with
Ether, per computational step
- Large decentralized computer
with millions of account objects.
35. Necessary APIs you need to know
Web3
● eth Ethereum blockchain related methods
● net Node’s network status
● personal Account functions and sending
● db Get/put for local LevelDB
● shh P2P messaging using Whisper
Play with web3 functionality http://thedapps.com/