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

    View Slide

  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

    View Slide

  3. Contents
    • What is Ethereum?
    • Ethereum Keys and Addresses
    • Ethereum Signatures
    • Ethereum Transaction
    • Interact with Smart Contract

    View Slide

  4. What is Ethereum?

    View Slide

  5. Ethereum Blockchain
    • It is the Ethereum Blockchain invented by Vitalik in 2013
    • Trustless on the blockchain
    • It's called a world computer

    View Slide

  6. Ethereum Blockchain
    https://ethereum.org/en/whitepaper/
    APPLY(S,TX) -> S'

    View Slide

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

    View Slide

  8. Etherscan
    https://etherscan.io/

    View Slide

  9. eth.rb
    • Let's take a look into the world of blockchain with eth.rb!
    • https://github.com/q9f/eth.rb

    View Slide

  10. Ethereum
    Keys and Addresses

    View Slide

  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/

    View Slide

  12. Eth::Key
    • The library can create private/public key pairs
    • This can also show the required address on ethereum

    View Slide

  13. Address
    0x4cbeFF8966586874362ce4313D8f80cD404838a3

    View Slide

  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)

    View Slide

  15. EIP-55
    • If the checksum is 8 or higher, the corresponding address letter is
    uppercase to prevent input errors.
    • EIP(Ethereum Improvement Proposals)

    View Slide

  16. EIP(Ethereum Improvement Proposals)
    https://eips.ethereum.org/EIPS/eip-55 https://eips.ethereum.org/EIPS/eip-721

    View Slide

  17. EIP-55
    • Addresses are not case sensitive
    • Can be veri
    fi
    ed if the checksum is used

    View Slide

  18. ENS
    • Ethereum Domain Name Service
    • kurotaky.eth
    https://ens.domains/
    https://eips.ethereum.org/EIPS/eip-137

    View Slide

  19. Ethereum Signatures

    View Slide

  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/

    View Slide

  21. personal_sign

    View Slide

  22. sign

    View Slide

  23. sign

    View Slide

  24. Signature.verify

    View Slide

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

    View Slide

  26. Chain ID

    View Slide

  27. Transaction

    View Slide

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

    View Slide

  29. Go Ethereum(geth)
    • Of
    fi
    cial Go implementation of the Ethereum protocol
    • geth --dev --http --ipcpath /tmp/geth.ipc
    https://geth.ethereum.org/

    View Slide

  30. geth

    View Slide

  31. Send ETH to another address
    • Geth (use http server)
    • use Eth::Client.create

    View Slide

  32. transfer_and_wait
    • 0.000000000000000001 = 1Wei
    • 0.000000000000000001 * 99000000000000000000 = 99ETH

    View Slide

  33. Eth::Unit

    View Slide

  34. Interact with Smart Contract

    View Slide

  35. Smart Contract
    • Can automatically execute contracts
    • Can execute programs on the blockchain

    View Slide

  36. Use Cases
    • DeFi (Decentralized Finance)
    • Identity (sign in with an ethereum account)
    • Cryptoeconomics
    • Stickers/badges
    • etc.

    View Slide

  37. Solidity
    https://docs.soliditylang.org/en/v0.8.16/introduction-to-smart-contracts.html#simple-smart-contract

    View Slide

  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

    View Slide

  39. Eth::Contract.from_
    fi
    le
    • Conversion from sol
    fi
    les to Ruby objects

    View Slide

  40. dummy.sol

    View Slide

  41. ABI & bin

    View Slide

  42. Deployment of Smart Contracts
    • Deployment of Smart Contracts
    • call() and transact_and_wait()

    View Slide

  43. Sample App 1
    Sign-In with Ethereum
    https://github.com/q9f/ethereum-on-rails

    View Slide

  44. View Slide

  45. User
    • username
    • eth_address
    • eth_nonce

    View Slide

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

    View Slide

  47. View Slide

  48. Let's try it!
    • This is a Rails application for creating Non Fungible Tokens
    • Please try it out !

    View Slide

  49. Conclusion

    View Slide

  50. Conclusion
    • Ethereum Blockchain Overview
    • How Ethereum Addresses Work and EIP
    • Overview of ethereum signatures
    • About executing smart contracts using eth.rb

    View Slide

  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

    View Slide

  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

    View Slide

  53. Thank You!
    @kurotaky

    View Slide