Use WebsocketProvider as HttpProvider is deprecated
This article applies to:
- BNB Smart Chain
An attempt to use web3.js with an EVM node fails with the following error:
Access to XMLHttpRequest at 'https://nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531'
from origin 'http://12.345.67.890' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
You are attempting to use a deprecated HttpProvider.
There is no CORS policy for WebSocket.
Use WebsocketProvider, which is the standard for web3.js.
See also Chainstack Docs: web3.js.