Closed nagdahimanshu closed 2 years ago
Commander start commands needs to fixed when handling api flags,
https://github.com/LiskHQ/lisk-sdk/blob/development/commander/src/bootstrapping/commands/start.ts#L180
https://github.com/LiskHQ/lisk-sdk/blob/development/commander/src/bootstrapping/commands/start.ts#L186
mode
should be modes
and should be an array for ex, ['ipc'] or ['ws']
Even after fixing this when we try to connect using wsClient we get the following error.
/lisk-sdk/node_modules/ws/lib/websocket.js:224
return abortHandshake(this, this._req, msg);
^
Error: WebSocket was closed before the connection was established
The RPC endpoint path was accidentally changed to /rpc
, but it is working.
The remaining issue will be resolved together in #7277
This still does not work when try to connect to testnet or mainnet:
const { apiClient } = require('lisk-elements');
async function main() {
const client = await apiClient.createWSClient('wss://testnet-service.lisk.com/rpc-v2');
console.log(await client.node.getNetworkStats());
}
main()
.catch(console.error);
Output:
> node src/client-test.js
Error: Unexpected server response: 502
at ClientRequest.<anonymous> (node_modules/ws/lib/websocket.js:767:7)
at ClientRequest.emit (node:events:513:28)
at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:674:27)
at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)
at TLSSocket.socketOnData (node:_http_client:521:22)
at TLSSocket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at TLSSocket.Readable.push (node:internal/streams/readable:228:10)
at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23)
Tried these URLS:
wss://testnet-service.lisk.com/rpc-v2
wss://testnet-service.lisk.com/rpc
wss://service.lisk.com/rpc-v2
wss://service.lisk.com/rpc
@blorgon1 this is not related, you're trying to connect to a service node:
I don't believe there's an official node with WS connection opened, here is a working code with a community node
const { apiClient } = require('@liskhq/lisk-client');
async function main() {
const client = await apiClient.createWSClient('wss://mainnet-api.lemii.dev/ws');
console.log(await client.node.getNetworkStats());
}
main()
.catch(console.error);
if you want to connect to lisk-service you need to use socket.io library
https://lisk.com/documentation/lisk-service/index.html#the-json-rpc-api
Thank you that is working for me.
Expected behavior
WSClient should create a connection without any issue
Actual behavior
Getting timeout while creating a connection
Steps to reproduce
createWSClient
from@liskhq/lisk-api-client
Which version(s) does this affect? (Environment, OS, etc...)
development