Skip to content

Commit

Permalink
fix: webSocket ping (#2594)
Browse files Browse the repository at this point in the history
* fix: copmly websocket ping request with jsonrpc schema

* style: webSocket

* Update webSocket.ts

---------

Co-authored-by: jxom <j@wevm.dev>
  • Loading branch information
kirillovmr and jxom committed Aug 7, 2024
1 parent d22855b commit 4b3c1e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/rude-onions-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Fixed websocket ping request not conforming to jsonrpc schema.
8 changes: 7 additions & 1 deletion src/utils/rpc/webSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
SocketClosedError,
WebSocketRequestError,
} from '../../errors/request.js'
import type { RpcRequest } from '../../types/rpc.js'
import {
type GetSocketRpcClientParameters,
type Socket,
Expand Down Expand Up @@ -71,7 +72,12 @@ export async function getWebSocketRpcClient(
cause: new SocketClosedError({ url: socket.url }),
})

socket.send('net_version')
const body: RpcRequest = {
jsonrpc: '2.0',
method: 'net_version',
params: [],
}
socket.send(JSON.stringify(body))
} catch (error) {
onError(error as Error)
}
Expand Down

0 comments on commit 4b3c1e6

Please sign in to comment.