00:00:01.920
Hello everyone! Today, I'm presenting about a Ruby library that connects with the blockchain, called Ethereum. My name is Yuta Kurotaki, and I have spoken at RubyKaigi 2018 and coached at Ruby conferences. I maintain the Ethereum Ruby library.
00:00:24.900
I will be discussing this topic today. First, what is Ethereum? Let me give you an overview of what Ethereum means. Ethereum is a blockchain established by Vitalik Buterin in 2013. It enables trustlessness on the blockchain.
00:00:39.000
Transactions and applications are currently running on Ethereum. It is sometimes referred to as a world computer or a global state because it propagates to nodes around the world and manages state across the globe. The Ethereum white paper contains a diagram showing that a transaction is executed to update the status. For instance, 10 Ether is sent from one address to another. This transaction is captured, and more blocks are chained together.
00:01:19.400
This is a service called Etherscan, where you can view all the historical transactions on the Ethereum blockchain on the web. You will see that many transactions are executed and captured in a single block. This information is publicly available, and once a block is created, it is not possible to alter it.
00:01:46.140
Now, let’s take a look into the world of blockchain with Ethereum Ruby (SRB). One thing we are all familiar with is blockchain wallets. For example, MetaMask is essential for sending and receiving Ether on the Ethereum blockchain.
00:02:00.000
This is an example of SRB code where you can easily create an address in Ruby. In SRB, a public key and private key are created, from which an Ethereum address is derived. This address will be unique and different from others. An Ethereum address starts with '0x', followed by 40 hexadecimal characters that derive from the public key.
00:02:38.160
The public key is obtained through the Keccak-256 function. The last 20 bytes are taken, prefixed with '0x', which forms your unique Ethereum address. You may have noticed when copying an address from MetaMask or any other wallet, it contains both uppercase and lowercase letters. This is a checksum designed to prevent human error in writing down long strings of characters, introduced in EIP-55.
00:04:18.240
The Ethereum address is case insensitive but contains letters formatted in a specific way to help detect typing errors. For example, if I had an address of 0xa33 and made a typing mistake, such as changing the last letter from 0xD to any invalid character, that error could be caught.
00:05:21.479
Recently, there has been the Ethereum Name Service (ENS), proposed in EIP-137 in 2016. ENS is increasingly being used. For instance, you may have noticed names such as k-u-r-o-t-a-k-y.eth on the internet.
00:06:05.400
Next, let's take a look at Ethereum signatures. The signature algorithm called ECDSA is used here for three purposes: to authorize payments or execute smart contracts; to prove that the signature is known and repeated; and to prove that no one has modified the transaction data since it was signed.
00:07:17.580
In SRB, you can use the 'personal_sign' method to sign applications. You may have been prompted to sign an application using MetaMask. For the signature, it should be prefixed to the message that is calculated using Keccak-256.
00:08:28.600
The result returns a hexadecimal signature. For example, if you are the owner of the private key, you can sign the transaction. This process involves checking the signature and recovering the public key using the recover method.
00:09:17.580
Including the chain ID when signing helps provide simple replay attack protection as described in EIP-155. By incorporating the chain ID before signing, the transaction cannot be displayed on another blockchain, and any change to the chain ID invalidates the signature.
00:10:27.720
There are many chains available, not only in Ethereum but also optimized platforms like Polygon and others, known as Layer 2 solutions. These chains often come with their own IDs.
00:11:27.010
Next, I will discuss transactions. There is a library called Geth, which is a node for the Ethereum blockchain. By connecting to this node, we can send transactions. In this example, we will run it in a test environment and observe a sample transaction output.
00:12:05.000
The first step will be creating a client to connect to the Ethereum node via HTTP. Then, we will create an Ethereum address and send some Ether to it.
00:12:49.200
Once we create an address, we check its initial balance. When we try to send 99 Ether, we execute the transfer and wait for the balance check.
00:13:01.000
In this case, one Wei is the smallest unit in Ethereum. Our balance calculations will reflect the transactions carried out.
00:13:13.000
Thank you. Lastly, I want to talk about smart contracts, which are programmable contracts that live on the blockchain. Smart contracts enable the automatic execution and enforcement of contract terms.
00:14:06.000
There are many use cases for smart contracts. Some examples include decentralized finance (DeFi), identity verification, and crypto economics. Smart contracts are commonly written in a language called Solidity. Here, we define 'get' and 'set' functions.
00:15:13.000
The source code written in Solidity is compiled using a compiler called 'Solc' and executes on the Ethereum Virtual Machine (EVM). This process is also utilized in SRB.
00:15:47.000
After compiling, ABI, bytecode, and opcode can be generated. The smart contract deployment process can be executed using the 'transact_and_wait' method to call the smart contract's methods.
00:17:08.000
The 'call' method in SRB is utilized to call read-only methods in a smart contract, which do not require additional transactions and do not write to the blockchain.
00:17:46.000
Conversely, the 'transact_and_wait' method executes a transaction on the blockchain when you want to perform an action that writes information to the blockchain. This includes providing sample application code.
00:18:44.000
This sample application demonstrates authentication in a decentralized way, allowing users to log in without the need to manage passwords on a web application. For instance, using MetaMask can be an example here.
00:19:27.000
There is also a sample application focusing on non-fungible tokens (NFTs). Please explore the applications, review the authoring code, and check it out on GitHub for further reference.
00:20:05.000
In conclusion, today I explained the overview of the Ethereum blockchain, the mechanisms of addresses, signatures, and EIPs with SRB, and how to effectively execute smart contracts using SRB.
00:20:40.000
Additionally, I believe that creating diverse Ethereum libraries beyond web3.js and ethers.js will be beneficial. I want to enable developers to create decentralized applications using Ruby.
00:21:12.000
Thank you to all the organizers, attendees, and contributors to this project, including Q9F, who introduced me to the world of Ethereum development.
00:21:41.000
Thank you so much for your attention!