Introduction
Solana Web3.js is a popular library for interacting with the Solana blockchain. However, it has a common error where it tries to calculate the WebSocket Secure (WSS) endpoint from an HTTP endpoint following a certain pattern. This can result in the code connecting to an incorrect WSS link, causing the ws error: Unexpected server response with code 404 or 503.
Solution
The current solution to this problem is to explicitly add both HTTP and WSS endpoints in the code. Here is a code snippet that you can use:
// RPC endpoint
const rpcEndpoint = "HTTP_ENDPOINT"; // Replace with your RPC endpoint
const wsEndpoint = "WSS_ENDPOINT"; // Replace with your WebSocket endpoint from Chainstack
const connection = new Connection(rpcEndpoint, {
wsEndpoint: wsEndpoint
});
Conclusion
By adding both endpoints explicitly, you can avoid the error and ensure that your code connects to the correct WSS link.
Feel free to contact Chainstack Support with any questions by emailing support@chainstack.com or submitting this form.
Comments
0 comments
Article is closed for comments.