Use WebsocketProvider as HttpProvider is deprecated
Issue
An attempt to use web3.js with an Ethereum node fails with the following error:
Access to XMLHttpRequest at 'https://user-name:pass-word-pass-word-pass-word@nd-123-456-789.p2pify.com'
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.
Cause
You are attempting to use a deprecated HttpProvider.
There is no CORS policy for WebSocket.
Solution
Use WebsocketProvider, which is the standard for web3.js.
See also Chainstack Docs: web3.js.
Comments
0 comments
Article is closed for comments.