Slide 1

Slide 1 text

How the Rubyist use Blockchain

Slide 2

Slide 2 text

WEB DEVELOPER GAME DEVELOPER 襟 儘 䓛⛳ @elct9620

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

I will talk about What is the Blockchain The examples use Ruby and Ethereum

Slide 5

Slide 5 text

What is the Blockchain

Slide 6

Slide 6 text

Linked List Cryptography Key-Value Data Store Distributed System

Slide 7

Slide 7 text

There is nothing new for us

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Cryptocurrency

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

So, how the Blockchain works?

Slide 12

Slide 12 text

Chain =~ Linked List

Slide 13

Slide 13 text

The Chain Block #1 Block #2 Block #3 Pointer Pointer

Slide 14

Slide 14 text

Ok, I think you already learned it!

Slide 15

Slide 15 text

But, we have to limit anyone to write it!!!

Slide 16

Slide 16 text

1. Proof of Work

Slide 17

Slide 17 text

1. Prevent mass request from somebody 2. Other people can verify in short time Cryptography

Slide 18

Slide 18 text

Use cryptography to resolve question!

Slide 19

Slide 19 text

Cryptography Network Hash start with “000” Workers Define a Question Broadcast

Slide 20

Slide 20 text

Cryptography Workers 000abcdefaaabc… Network Try hash block Submit

Slide 21

Slide 21 text

Cryptography Network 000abcdefaaabc Block Created Verify result Accept

Slide 22

Slide 22 text

Wait! The same content will get the same hash result!

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

We add a random “Proof” string with block data

Slide 25

Slide 25 text

So, the worker should spend the time

Slide 26

Slide 26 text

And others can check it in short time

Slide 27

Slide 27 text

If we receive many correct answers…

Slide 28

Slide 28 text

Which one should accept?

Slide 29

Slide 29 text

2. Byzantine Generals Problem

Slide 30

Slide 30 text

Distributed 1. Longest is right 2. 51% node think it is right

Slide 31

Slide 31 text

But, we didn’t discuss the algorithm in this talk

Slide 32

Slide 32 text

And last

Slide 33

Slide 33 text

How the Blockchain save data?

Slide 34

Slide 34 text

Merkle Tree

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

Very useful to update and verify data

Slide 37

Slide 37 text

But read will spend more time

Slide 38

Slide 38 text

Should I use pure ruby gem to operate blockchain?

Slide 39

Slide 39 text

It is hard to implement the same API in pure Ruby

Slide 40

Slide 40 text

Use the existed API to operate Blockchain.

Slide 41

Slide 41 text

But, you can implement blockchain in Ruby

Slide 42

Slide 42 text

Example Ethereum’s IPC Use Ruby to operate Ethereum

Slide 43

Slide 43 text

IPC =~ UnixSocket

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

How to get IPC and comminuted with it?

Slide 46

Slide 46 text

IPC 1. Ethereum Wallet 2. brew install geth 3. Compile from source code

Slide 47

Slide 47 text

“geth —light —testnet”

Slide 48

Slide 48 text

But I suggest using Ethereum Wallet

Slide 49

Slide 49 text

Because you can find IPC file very easy

Slide 50

Slide 50 text

But how to use UnixSocket to operate Ethereum?

Slide 51

Slide 51 text

JSON-RPC 2.0

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

And it always ends with a linefeed (\n)

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

Now, we can interact with Ethereum in Ruby

Slide 58

Slide 58 text

But the result has many hash value

Slide 59

Slide 59 text

What are the meaning and real data?

Slide 60

Slide 60 text

Ethereum Data 1. Call another API to get transaction value 2. Read from “data” depend on ABI

Slide 61

Slide 61 text

If we just want to know transaction value

Slide 62

Slide 62 text

It always contains in API response

Slide 63

Slide 63 text

So, we talk about smart contract event

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

But we got the data in hex

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

It always returns the 32byte hex string for us

Slide 68

Slide 68 text

So, we need ABI to help us know the data type

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

Demo - Subscribe event and get data

Slide 71

Slide 71 text

Now, we know what can we do on the Ethereum

Slide 72

Slide 72 text

And last, is there has any useful resource?

Slide 73

Slide 73 text

Ruby Reference 1. digest-sha3 2. rlp 3. ruby-ethereum 4. Naivechain.rb

Slide 74

Slide 74 text

Conclusion

Slide 75

Slide 75 text

Build a blockchain in Ruby can help us learn it

Slide 76

Slide 76 text

And didn’t try to write a client in pure ruby

Slide 77

Slide 77 text

THANKS