sui
sui copied to clipboard
Typescript sdk subscribe event error on mainnet.
Steps to Reproduce Issue
const { SuiClient, getFullnodeUrl, SuiHTTPTransport } = require("@mysten/sui.js/client")
const { WebSocket } = require('ws')
const client = new SuiClient({
transport: new SuiHTTPTransport({
url: getFullnodeUrl("mainnet"),
WebSocketConstructor: WebSocket,
}),
});
async function handleEvent() {
const unsubscribe = await client.subscribeEvent({
filter: {
Package: '...',
},
onMessage(event) {
console.log("event:", event)
},
})
}
handleEvent().catch((error) => {
console.error(error)
process.exitCode = 1
})
The exact same code works fine when the url is set 'testnet', but after switching to 'mainnet', It gives error like this.
JsonRpcError: Invalid params
at /sui-script/node_modules/@mysten/sui.js/dist/cjs/client/rpc-websocket-client.js:103:15
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async RpcSubscription.subscribe (/sui-script/node_modules/@mysten/sui.js/dist/cjs/client/rpc-websocket-client.js:197:31)
at async WebsocketClient.subscribe (/sui-script/node_modules/@mysten/sui.js/dist/cjs/client/rpc-websocket-client.js:111:5)
at async SuiHTTPTransport.subscribe (/sui-script/node_modules/@mysten/sui.js/dist/cjs/client/http-transport.js:99:25)
at async handleEvent (sui-script/grab.js:43:22) {
code: -32602,
type: 'InvalidParams'
}
System Information
- OS: Mac M1 OS version: 14.4.1
- Node version: v21.7.3
This is a known issue. The WS server is not very stable and it fails randomly. We'd recommend to use a polling method for whatever you need to do. See also: #14355