cosmology-tech / telescope

A TypeScript Transpiler for Cosmos Protobufs ⚛️
https://cosmology.zone/products/telescope
Apache License 2.0
146 stars 43 forks source link

web socket client #94

Open pyramation opened 2 years ago

pyramation commented 2 years ago

reference implementations

atmoner commented 2 years ago

reference implementations

You can refer to this file for a minimum code, it simply retrieves the new blocks live from websocket of tendermint :+1:

import WebSocket from 'ws';
const ws = new WebSocket('ws://osmosis.strange.love:26657/websocket');

ws.on('open', function open() {
  console.log('Connected on Osmosis blockchain from WebSocket');
  ws.send(JSON.stringify({
    "method":"subscribe",
    "params": ["tm.event='NewBlock'"],
    "id":"1",
    "jsonrpc":"2.0"
  }));
});

ws.on('close', function close() {
  console.log('disconnected');
});

ws.on('message', function incoming(data) {
  var finalData = JSON.parse(data.toString('utf-8'));
  if (finalData.result.data)
    console.log(finalData.result);
}); 

https://github.com/atmoner/cosmos-websocket/blob/main/osmosis-websocket.js

image

The doc is here: https://docs.tendermint.com/master/rpc/

pyramation commented 2 years ago

thanks @atmoner ! this is much appreciated :)

jonator commented 1 year ago

Also; keplr-wallet TendermentTxTracer

https://github.com/chainapsis/keplr-wallet/blob/97a65130583778b09e59016e0e7c95a296641c94/packages/cosmos/src/tx-tracer/index.ts#L9-L308

hoangdv2429 commented 1 year ago

@Zetazzz hey, do you want to discuss on how we will implement this ? I can't reach to you through discord so tagging you here.

Zetazzz commented 1 year ago

@hoangdv2429 Hey, sorry for late response. yes, I think we can discuss more on discord.