Upgrade to Pro — share decks privately, control downloads, hide ads and more …

2018 - How the Rubyist use Blockchain

2018 - How the Rubyist use Blockchain

The talks about ruby and blockchain in rubyelixirconftw.


May 07, 2018

More Decks by 蒼時弦や

Other Decks in Technology


  1. How the Rubyist use Blockchain

  2. WEB DEVELOPER GAME DEVELOPER 襟 儘 䓛⛳ @elct9620

  3. None
  4. I will talk about What is the Blockchain The examples

    use Ruby and Ethereum
  5. What is the Blockchain

  6. Linked List Cryptography Key-Value Data Store Distributed System

  7. There is nothing new for us

  8. None
  9. Cryptocurrency

  10. None
  11. So, how the Blockchain works?

  12. Chain =~ Linked List

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

  14. Ok, I think you already learned it!

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

  16. 1. Proof of Work

  17. 1. Prevent mass request from somebody 2. Other people can

    verify in short time Cryptography
  18. Use cryptography to resolve question!

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

  20. Cryptography Workers 000abcdefaaabc… Network Try hash block Submit

  21. Cryptography Network 000abcdefaaabc Block Created Verify result Accept

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

  23. None
  24. We add a random “Proof” string with block data

  25. So, the worker should spend the time

  26. And others can check it in short time

  27. If we receive many correct answers…

  28. Which one should accept?

  29. 2. Byzantine Generals Problem

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

    is right
  31. But, we didn’t discuss the algorithm in this talk

  32. And last

  33. How the Blockchain save data?

  34. Merkle Tree

  35. None
  36. Very useful to update and verify data

  37. But read will spend more time

  38. Should I use pure ruby gem to operate blockchain?

  39. It is hard to implement the same API in pure

  40. Use the existed API to operate Blockchain.

  41. But, you can implement blockchain in Ruby

  42. Example Ethereum’s IPC Use Ruby to operate Ethereum

  43. IPC =~ UnixSocket

  44. None
  45. How to get IPC and comminuted with it?

  46. IPC 1. Ethereum Wallet 2. brew install geth 3. Compile

    from source code
  47. “geth —light —testnet”

  48. But I suggest using Ethereum Wallet

  49. Because you can find IPC file very easy

  50. But how to use UnixSocket to operate Ethereum?

  51. JSON-RPC 2.0

  52. None
  53. None
  54. And it always ends with a linefeed (\n)

  55. None
  56. None
  57. Now, we can interact with Ethereum in Ruby

  58. But the result has many hash value

  59. What are the meaning and real data?

  60. Ethereum Data 1. Call another API to get transaction value

    2. Read from “data” depend on ABI
  61. If we just want to know transaction value

  62. It always contains in API response

  63. So, we talk about smart contract event

  64. None
  65. But we got the data in hex

  66. None
  67. It always returns the 32byte hex string for us

  68. So, we need ABI to help us know the data

  69. None
  70. Demo - Subscribe event and get data

  71. Now, we know what can we do on the Ethereum

  72. And last, is there has any useful resource?

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

  74. Conclusion

  75. Build a blockchain in Ruby can help us learn it

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

  77. THANKS