The talks about ruby and blockchain in rubyelixirconftw.
How the Rubyist useBlockchain
View Slide
WEB DEVELOPERGAME DEVELOPER襟儘䓛⛳@elct9620
I will talk aboutWhat is the BlockchainThe examples use Ruby and Ethereum
What is the Blockchain
Linked ListCryptographyKey-Value Data StoreDistributed System
There is nothing new for us
Cryptocurrency
So, how the Blockchain works?
Chain =~ Linked List
The ChainBlock #1Block #2Block #3PointerPointer
Ok, I think you already learned it!
But, we have to limit anyone to write it!!!
1. Proof of Work
1. Prevent mass request from somebody2. Other people can verify in short timeCryptography
Use cryptography to resolve question!
CryptographyNetworkHash start with “000”WorkersDefine a QuestionBroadcast
CryptographyWorkers000abcdefaaabc…NetworkTry hash blockSubmit
CryptographyNetwork000abcdefaaabcBlock CreatedVerify resultAccept
Wait!The same content will get the same hash result!
We add a random “Proof” string with block data
So, the worker should spend the time
And others can check it in short time
If we receive many correct answers…
Which one should accept?
2. Byzantine Generals Problem
Distributed1. Longest is right2. 51% node think it is right
But, we didn’t discuss the algorithm in this talk
And last
How the Blockchain save data?
Merkle Tree
Very useful to update and verify data
But read will spend more time
Should I use pure ruby gem to operate blockchain?
It is hard to implement the same API in pure Ruby
Use the existed API to operate Blockchain.
But, you can implement blockchain in Ruby
ExampleEthereum’s IPCUse Ruby to operate Ethereum
IPC =~ UnixSocket
How to get IPC and comminuted with it?
IPC1. Ethereum Wallet2. brew install geth3. Compile from source code
“geth —light —testnet”
But I suggest using Ethereum Wallet
Because you can find IPC file very easy
But how to use UnixSocket to operate Ethereum?
JSON-RPC 2.0
And it always ends with a linefeed (\n)
Now, we can interact with Ethereum in Ruby
But the result has many hash value
What are the meaning and real data?
Ethereum Data1. Call another API to get transaction value2. Read from “data” depend on ABI
If we just want to know transaction value
It always contains in API response
So, we talk about smart contract event
But we got the data in hex
It always returns the 32byte hex string for us
So, we need ABI to help us know the data type
Demo - Subscribe event and get data
Now, we know what can we do on the Ethereum
And last, is there has any useful resource?
Ruby Reference1. digest-sha32. rlp3. ruby-ethereum4. Naivechain.rb
Conclusion
Build a blockchain in Ruby can help us learn it
And didn’t try to write a client in pure ruby
THANKS