Slide 1

Slide 1 text

Ethereum for Ruby Yuta Kurotaki

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

What is Ethereum?

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Etherscan https://etherscan.io/

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

Ethereum Keys and Addresses

Slide 11

Slide 11 text

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/

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

Address 0x4cbeFF8966586874362ce4313D8f80cD404838a3

Slide 14

Slide 14 text

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)

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Ethereum Signatures

Slide 20

Slide 20 text

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/

Slide 21

Slide 21 text

personal_sign •

Slide 22

Slide 22 text

sign

Slide 23

Slide 23 text

sign

Slide 24

Slide 24 text

Signature.verify

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

Chain ID

Slide 27

Slide 27 text

Transaction

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

geth

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

Eth::Unit

Slide 34

Slide 34 text

Interact with Smart Contract

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

dummy.sol

Slide 41

Slide 41 text

ABI & bin

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

User • username • eth_address • eth_nonce

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

Conclusion

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

Thank You! @kurotaky