Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript sdk subscribe event error on mainnet. #17661

Closed
KyrinCode opened this issue May 11, 2024 · 1 comment
Closed

Typescript sdk subscribe event error on mainnet. #17661

KyrinCode opened this issue May 11, 2024 · 1 comment
Labels

Comments

@KyrinCode
Copy link

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
@KyrinCode KyrinCode changed the title Sui Code Bug or Feature Request Typescript sdk subscribe event error on mainnet. May 11, 2024
@stefan-mysten
Copy link
Contributor

stefan-mysten commented May 13, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants