4

I'm testing out Metamask under Chrome. I see that current Metamask (version 4.5.3) injects web3 version 0.20.3. Since web3 has a long history of volatile API, I would prefer to always stick to a specific version (possibly 1.0), independently of the one provided by Metamask.

In my understanding of how Metamask works, this should not be possible and, indeed, I've found nothing googling out this issue. Anyway, I wanted to ask the community, maybe I'm overlooking something.

Thanks.

1 Answers1

7

Yes, you can use whatever version of web3 you want.

Just include the relevant <script> tag, and then do:

web3 = new Web3(web3.currentProvider);

This is how you should always use MetaMask. See, e.g., https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md and https://github.com/ethereum/wiki/wiki/JavaScript-API#adding-web3.

user19510
  • 27,999
  • 2
  • 30
  • 48
  • 1
    It's also worth noting that currently MetaMask does not support web3 1.0 or later. https://github.com/MetaMask/metamask-extension/issues/3639 – DanF Apr 06 '18 at 03:55
  • Good point, thanks @DanF. From my experience, it's only event subscription that don't work. (I suppose other kinds of subscriptions would have the same problem.) – user19510 Apr 06 '18 at 07:03
  • "Just include the relevant – Ytsen de Boer May 15 '18 at 20:16
  • 1
    <script src="/path/to/the/web3.js/you/want/to/use"></script> – user19510 May 15 '18 at 20:17
  • Thank you for a swift reply. With that line of code you suggest I can "bundle" the web3 version I like (choose web3.min.js version 1.0). But it is not clear to me how I can verify that my client side code is actually using the bundled version? Can I print out the version, for example? – Ytsen de Boer May 15 '18 at 21:43
  • I am asking this in a separate question with some context: https://ethereum.stackexchange.com/questions/48598/how-to-bundle-own-web3-version-and-using-metamask – Ytsen de Boer May 15 '18 at 22:09
  • web3.version.api will print which version your site is running – Barrard Jan 12 '19 at 07:36