wuminzhe / scale_rb

MIT License
4 stars 2 forks source link

Unsure how to use `AbstractWsClient` #5

Open ltfschoen opened 5 months ago

ltfschoen commented 5 months ago

@wuminzhe @itering recently i presented this repository at a BlockspaceDevRel event as part of Consensus 2024, as I was interested in encouraging its use. Here are the slides https://hackmd.io/@ltfschoen/Hy25QTH40#/. I have a question, is it possible to use this scale_rb library to connect to a local Substrate-based node using Ws instead of Http? If so how? There is a AbstractWsClient here https://github.com/wuminzhe/scale_rb/blob/main/lib/client/abstract_ws_client.rb#L6, but could you please share an example of how to use it? Or if the Ws capability is incomplete, do you have any tips on how I could add that capability? Should it be added similar to the deprecated repository https://github.com/itering/substrate_client.rb?tab=readme-ov-file#supported-rpc-methods where it was possible to connect using Ws using:

require "substrate_client"
client = SubstrateClient.new("wss://kusama-rpc.polkadot.io/")

I was only able to connect using Http in my fork of this repo in this example https://github.com/ltfschoen/scale_rb/blob/easya/example01/main.rb#L3 based on reviewing the code in this repository. The reason why I want to connect using Websockets is because most of the available parachain endpoints are Ws endpoints, I'd only use Http for connecting to a Substrate-based node running on localhost.

wuminzhe commented 5 months ago

@ltfschoen Sorry for being late. Thanks for presenting this library. I haven't done much with websockets yet. I didn't have much time to it before. But I will have more time to work on it next month.

wuminzhe commented 5 months ago

I'll let you know once I start. @ltfschoen

wuminzhe commented 4 months ago

https://x.com/wuminzhe/status/1810555964296413455

@ltfschoen I'm writing the websocket client. I'll update the code after it is ready

wuminzhe commented 4 months ago
WsClient.start('wss://polkadot-rpc.dwellir.com') do |client|
  block_hash = client.chain_getBlockHash(100)
  runtime_version = client.state_getRuntimeVersion(block_hash)
  puts runtime_version
end
WsClient.start('wss://polkadot-rpc.dwellir.com') do |client|
  client.chain_subscribeNewHead do |head|
    puts head
  end
end
wuminzhe commented 4 months ago

PR: https://github.com/wuminzhe/scale_rb/pull/6

wuminzhe commented 4 months ago

@ltfschoen I have added the ws_client and updated the http_client. You can try them by using 0.3.0.

And, I also added an examples dir to show how to use them. I'll add more examples.

ltfschoen commented 4 months ago

@wuminzhe are you going to be maintaining this repo under the Polkadot Tooling Collective?