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.

6

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.

| improve this answer | |
  • It's also worth noting that currently MetaMask does not support web3 1.0 or later. github.com/MetaMask/metamask-extension/issues/3639 – DanF Apr 6 '18 at 3: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 6 '18 at 7:03
  • "Just include the relevant <script> tag, and then do" ... I'm a bit of a javascript noob, but what is "the relevant <script> tag" here exactly? – 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.