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

Ethereum for Ruby

Yuta Kurotaki
September 10, 2022

Ethereum for Ruby

RubyKaigi 2022
Mie Center for the Arts, Mie, Japan

Ethereum for Ruby
https://rubykaigi.org/2022/presentations/kurotaky.html#day3

Yuta Kurotaki

September 10, 2022
Tweet

More Decks by Yuta Kurotaki

Other Decks in Technology

Transcript

  1. Ethereum for Ruby Yuta Kurotaki

  2. Yuta Kurotaki @kurotaky RubyKaigi Speaker 2018 RailsGirls Coach 4,7~10,12,13th Yokohama.rb,

    K-Ruby Kagoshima RubyKaigi 01 Organizer Goods Sponsor (SUZURI, GMO Pepabo, Inc.) eth.rb Maintainer
  3. Contents • What is Ethereum? • Ethereum Keys and Addresses

    • Ethereum Signatures • Ethereum Transaction • Interact with Smart Contract
  4. What is Ethereum?

  5. Ethereum Blockchain • It is the Ethereum Blockchain invented by

    Vitalik in 2013 • Trustless on the blockchain • It's called a world computer
  6. Ethereum Blockchain https://ethereum.org/en/whitepaper/ APPLY(S,TX) -> S'

  7. Ethereum Blockchain https://ethereum.org/en/whitepaper/

  8. Etherscan https://etherscan.io/

  9. eth.rb • Let's take a look into the world of

    blockchain with eth.rb! • https://github.com/q9f/eth.rb
  10. Ethereum Keys and Addresses

  11. Blockchain Wallet • When users create a wallet such as

    MetaMask, an address of 0xabc.... is created. • This address is required on Ethereum https://metamask.io/
  12. Eth::Key • The library can create private/public key pairs •

    This can also show the required address on ethereum
  13. Address 0x4cbeFF8966586874362ce4313D8f80cD404838a3

  14. Address • Calculate hash value of public key with Keccak256

    • Public key = K, last 20bytes of Keccak256(K) • Returns with 0x; 42 characters (40 without 0x)
  15. EIP-55 • If the checksum is 8 or higher, the

    corresponding address letter is uppercase to prevent input errors. • EIP(Ethereum Improvement Proposals)
  16. EIP(Ethereum Improvement Proposals) https://eips.ethereum.org/EIPS/eip-55 https://eips.ethereum.org/EIPS/eip-721

  17. EIP-55 • Addresses are not case sensitive • Can be

    veri fi ed if the checksum is used
  18. ENS • Ethereum Domain Name Service • kurotaky.eth https://ens.domains/ https://eips.ethereum.org/EIPS/eip-137

  19. Ethereum Signatures

  20. Ethereum Signatures • ECDSA (Eliptic Curve Digital Signature Algorithm) •

    This is used for three purposes 1. proof of authorization to make ETH payments or execute smart contracts 2. proof that the signature is non-repudiation 3. proof that no one has modi fi ed the transaction data since it was signed https://ethereum.org/en/developers/docs/transactions/
  21. personal_sign •

  22. sign

  23. sign

  24. Signature.verify

  25. EIP-155 https://eips.ethereum.org/EIPS/eip-155

  26. Chain ID

  27. Transaction

  28. Transaction https://ethereum.org/en/whitepaper/

  29. Go Ethereum(geth) • Of fi cial Go implementation of the

    Ethereum protocol • geth --dev --http --ipcpath /tmp/geth.ipc https://geth.ethereum.org/
  30. geth

  31. Send ETH to another address • Geth (use http server)

    • use Eth::Client.create
  32. transfer_and_wait • 0.000000000000000001 = 1Wei • 0.000000000000000001 * 99000000000000000000 =

    99ETH
  33. Eth::Unit

  34. Interact with Smart Contract

  35. Smart Contract • Can automatically execute contracts • Can execute

    programs on the blockchain
  36. Use Cases • DeFi (Decentralized Finance) • Identity (sign in

    with an ethereum account) • Cryptoeconomics • Stickers/badges • etc.
  37. Solidity https://docs.soliditylang.org/en/v0.8.16/introduction-to-smart-contracts.html#simple-smart-contract

  38. Solidity Compiler dummy.sol Solidity Compiler (solc) byte code 6080604052..... EVM

    (Ethereum Virtual Machine) ABI (Application Binary Interface) EVM opcode PUSH1 0x80 PUSH1 0x40 MSTORE
  39. Eth::Contract.from_ fi le • Conversion from sol fi les to

    Ruby objects
  40. dummy.sol

  41. ABI & bin

  42. Deployment of Smart Contracts • Deployment of Smart Contracts •

    call() and transact_and_wait()
  43. Sample App 1 Sign-In with Ethereum https://github.com/q9f/ethereum-on-rails

  44. None
  45. User • username • eth_address • eth_nonce

  46. Sample App 2 Non-Fungible Token App https://gihyo.jp/magazine/wdpress/archive/2022/vol130 https://github.com/kurotaky/sample-rails-dapp

  47. None
  48. Let's try it! • This is a Rails application for

    creating Non Fungible Tokens • Please try it out !
  49. Conclusion

  50. Conclusion • Ethereum Blockchain Overview • How Ethereum Addresses Work

    and EIP • Overview of ethereum signatures • About executing smart contracts using eth.rb
  51. Future of eth.rb • Language diversity is important so that

    Ruby can also connect with the Ethereum world! • More examples of creating DApps with Ruby and Rails • Make it easy to connect to existing Rails applications
  52. Acknowledgements • @ethmarek • He brought me into the world

    of Ethereum.rb • @q9f • He promotes and maintains the eth.rb project with us • GMO Pepabo Web3 Development Team • RubyKaigi staff, organizers, committers and attendees
  53. Thank You! @kurotaky