diff --git a/.changeset/rude-onions-draw.md b/.changeset/rude-onions-draw.md new file mode 100644 index 0000000000..ccc0040fb8 --- /dev/null +++ b/.changeset/rude-onions-draw.md @@ -0,0 +1,5 @@ +--- +"viem": patch +--- + +Fixed websocket ping request not conforming to jsonrpc schema. diff --git a/src/utils/rpc/webSocket.ts b/src/utils/rpc/webSocket.ts index e83faa3488..f63e84d34b 100644 --- a/src/utils/rpc/webSocket.ts +++ b/src/utils/rpc/webSocket.ts @@ -4,6 +4,7 @@ import { SocketClosedError, WebSocketRequestError, } from '../../errors/request.js' +import type { RpcRequest } from '../../types/rpc.js' import { type GetSocketRpcClientParameters, type Socket, @@ -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) }