As per https://web3js.readthedocs.io/en/1.0/web3.html#value the HttpProvider is deprecated. Using the web3 beta 1.0.

It seems funny to me that it would be being deprecated. But I am curious as to how I would transition to something else like websockets in the future using a service like Infura.

My current code is something like:

import Web3 from 'web3';

let web3;

if (typeof window !== 'undefined' && typeof window.web3 !== 'undefined'){
    //We are in the browser and Metamask is running
    web3 = new Web3(window.web3.currentProvider);
} else {
    //We are on the server *OR* the user is not running Metamask
    const provider = new Web3.providers.HttpProvider(
    web3 = new Web3(provider);

export default web3;

Edit: From @Ismael how to currently implement the Infura Websocket provider Infura web3 provider for Events (.get & .watch) see answer by Maheshmurthy. As far as I know it's not production ready and doesn't require an API key yet : https://github.com/INFURA/infura/issues/97 .

Maybe a better question is: Is there a short explanation about why httpProviders are deprecated other than: no subscriptions and they are better. And for a beginner developing with web3 -- If I just switch providers to wss what differences can I expect? Infura specific not necessary.

  • The second answer from that question has an example how to use infura with websockets.
    – Ismael
    Commented Jul 31, 2018 at 1:36
  • @Ismael Yeah... the second answer helps with the implementation. I would not say it is a duplicate question though -- they are more interested in subscribing to events. I just want to stay up to date on how to best implement a provider in the future. This wasn't really my best question, will update with your link. Commented Aug 2, 2018 at 16:24
  • Looks like your question is what's the difference between WS and HTTP... pretty much off topic here. Commented Aug 4, 2018 at 10:12
  • Yah its a bad question on my part. I'm interested if websockets will help my async await promises resolve larger arrays using the .call() method. I will maybe test it out and see how it goes, but its in beta -- and again I'm kinda new to this. Some history on Websocket Provider for others github.com/ethereum/web3.py/issues/566 Commented Aug 10, 2018 at 0:58


Browse other questions tagged or ask your own question.