Sha256: 713e8074f13f5d3a534a3cbf36be07bdb07728d556a4e6425d40b9c00efbb8c5
Contents?: true
Size: 692 Bytes
Versions: 3
Compression:
Stored size: 692 Bytes
Contents
require 'scale_rb' # Unsubscribe after receiving 4 new heads ScaleRb::WsClient.start('wss://polkadot-rpc.dwellir.com') do |client| count = 0 subscription_id = client.chain_subscribeNewHead do |head| count += 1 if count < 5 block_number = head[:number].to_i(16) block_hash = client.chain_getBlockHash(block_number) puts "Received new head at height: #{block_number}, block hash: #{block_hash}" else unsub_result = client.chain_unsubscribeNewHead(subscription_id) puts "Unsubscribe #{subscription_id} #{unsub_result === true ? 'succeeded' : 'failed'}" end end puts "Subscribed to new heads with subscription id: #{subscription_id}" end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
scale_rb-0.5.1 | examples/ws_client_3.rb |
scale_rb-0.5.0 | examples/ws_client_3.rb |
scale_rb-0.4.2 | examples/ws_client_3.rb |