<style>
.reveal {
font-size: 24px;
}
</style>
# Explore how to build your idea on Polkadot using Ruby
`---`
- Intro to Ruby, Substrate (including SCALE codec), Polkadot
- History of core Ruby tools to interact with Polkadot
- [Polkadot Tooling Collective](https://github.com/polkadot-tooling-collective/collective/)
Author: [@ltfschoen](https://x.com/ltfschoen)
Team: BlockDevRels

---
## What Goal?
- Quickly use Ruby using ScaleRb to interact with Polkadot
- Interact with nodes
- Synchronize data through JSON-RPC
Note:
- This was the substrate_rb vision in their grant proposal
---
## Why Ruby?
- Abstract language
- Mature community and ecosystem
- Popular among startups and small businesses
- Ruby on Rails
- On-ramp to Rust and Elixir
---
### What is SCALE codec?
- SCALE codec is a lightweight, efficient, binary serialization and deserialization codec used by Substrate
- SCALE codec encodes and decodes input and output interactions between RPCs and the Substrate-based runtime using the SCALE data format
- Reference:
- SCALE in official Substrate documentation https://docs.substrate.io/reference/scale-codec/
- SCALE in Polkadot Blockchain Academy https://polkadot-blockchain-academy.github.io/pba-book/substrate/scale/page.html
---
### What is Substrate?
- Blockchain framework that allows developers to create custom blockchains (including parachains) and tools, for the Polkadot network
- Substrate is open-source and future-proof
- Helps build a decentralized, interoperable, and multi-chain internet
- Reference:
- Official Substrate documentation https://docs.substrate.io
- Merged into the Polkadot SDK https://github.com/paritytech/polkadot-sdk/tree/master/substrate
---
## Why Polkadot?
- Interoperability
- Shared security
- Agile Coretime
- efficiently utilize Polkadot network resources
- economic flexibility
- Polkadot SDK https://github.com/paritytech/polkadot-sdk
---
## History of using Ruby with Polkadot
- Grant from W3F https://github.com/w3f/General-Grants-Program/blob/master/grants/speculative/ruby_substrate_api.md
- JSON-RPC API client and libraries implemented in Ruby to interact with Substrate-based nodes
- Implementation of low-level data formats
- Substrate types and metadata support
- Ruby-based scale codec and API implementation
---

---
## History of using Ruby with Polkadot (Continued)
- Initially built:
- Substrate Client (substrate_client) https://github.com/itering/substrate_client.rb
- Features: Library of interfaces implemented in Ruby to query and interact with Substrate-based nodes.
- Status: Deprecated (merged into Scale.Rb)
- Scale Ruby (Scale.Rb) https://github.com/itering/scale.rb
- Features:
- Ruby SCALE Codec Library & Substrate Client
- Connect to a Substrate node
- List all types implemented for a chain
- Get storage using custom types
- Status: Deprecated (merged into Scale_Rb)
- Scale Ruby (Scale_Rb) https://github.com/wuminzhe/scale_rb
```mermaid
gantt
%% https://mermaid.js.org/syntax/gantt.html
title Polkadot and Substrate using Ruby
dateFormat YY-MM
tickInterval 6month
axisFormat %Y-%m
todayMarker stroke-width:5px,stroke:#0f0,opacity:0.5
section scale.rb
Build :done, 2019-10, 1095d
section subtrate_client
Build :done, 2020-03, 365d
section scale_rb
Build :active, 2023-09, 180d
```
---
## Demo using ScaleRb?
----
### Run Polkadot node locally using Pop! CLI
* Clone https://github.com/ltfschoen/pop-cli
* Checkout branch "easya"
```bash
git clone https://github.com/ltfschoen/pop-cli
cd pop-cli
git fetch origin easya:easya
git checkout easya
```
* Follow README instructions
* Use Pop! CLI to run local node
----

----

---
### Query node using ScaleRb
* Clone https://github.com/ltfschoen/scale_rb
* Added Dockerfile similar to substrate_client
* Install Rust in Dockerfile to use blake2b_rs Rust dependency
* Checkout branch "easya"
```bash
git clone https://github.com/ltfschoen/scale_rb
cd scale_rb
git fetch origin easya:easya
git checkout easya
```
* Follow README instructions
Note:
- Use docker-compose. e.g.
- https://betterprogramming.pub/setting-up-rails-with-postgres-using-docker-426c853e8590
- https://github.com/docker-library/ruby/blob/53646d3dc96008bd20218a4d9aeb5695619fb4f7/3.3/bookworm/Dockerfile
----
```ruby [2-5]
# example01/main.rb
require "scale_rb"
# replace port with that exposed by node generated with Pop! CLI
methods = ScaleRb::HttpClient.rpc_methods("http://127.0.0.1:9944")
puts methods
```
----
```bash
ruby example01/main.rb
```
----

---
## Challenges
- Beginner
- Use REPL `irb` or `pry` to interact with ScaleRb and custom chain
- Intermediate
- Modify your custom chain and interact with it using ScaleRb
Note:
- Example: "adder" collator template https://github.com/paritytech/polkadot-sdk/tree/master/polkadot/parachain/test-parachains/adder/collator
----
## Challenges (Continued)
- Advanced
- Create CLI tool or game using Ruby or game that interacts with the custom chain that you scaffolded with Pop! CLI
- Write tests using Unit Test or RSpec
```ruby
gem install rspec
bundle install
rspec --init
```
- Write Behaviour Driven Development tests using Cucumber
- **Example 02:**
- https://github.com/wuminzhe/scale_rb/pull/4
.
```graphviz
digraph dot {
node [fontname=Arial, shape=box]
edge [style=dashed]
User->ParachainDAO
ParachainDAO->Cores
}
```
----
## Challenges (Continued)
- Advanced
- Create CLI tool that interacts with the Broker pallet of the Polkadot SDK to interact with Agile Coretime
- Presentation on Coretime https://hackmd.io/opdQFGGCSVyoYpfIkEvXoQ?view#/
---
<!-- .slide: data-background="https://hackmd.io/_uploads/BkBVT8INC.png" data-background-color="#000" -->
---
## Future
- Easy
- Create an OpenGov discussion recommending EasyA Tooling Tracks covering Ruby and Polkadot
- Use Ruby with Sinatra (light-weight server)
- Find out about Polkadot Tooling Collective
- https://forum.polkadot.network/t/proposing-the-polkadot-tooling-collective-potoc/6915
- https://github.com/polkadot-tooling-collective/constitution
- Contribute to diversity of Polkadot Tooling
- Ask questions in Substrate and Polkadot StackExchange
- https://substrate.stackexchange.com/
- Find out about OpenGov
- https://polkadot-blockchain-academy.github.io/pba-book/polkadot/opengov/page.html
- Intermediate
- Use Ruby on Rails (scaffold API with MVC and RESTful routes)
- Advanced
- Use similar Rust implementations of ScaleRb:
- SubXT https://github.com/paritytech/subxt
- SubAlfred https://github.com/hack-ink/subalfred
- Write a Ruby implementation of JAM
- https://github.com/gavofyork/graypaper
---
## Support
Ask any question to BlockDevRels Team! :100:
{"slideOptions":"{\"transition\":\"slide\",\"showNotes\":false}","contributors":"[{\"id\":\"2919a303-fc3e-4772-931d-46f52dd5a610\",\"add\":18054,\"del\":7964}]","title":"Explore how to build your idea on Polkadot using Ruby","description":"---"}