Metamask stopping to inject web3.js
Asked Answered
I

2

5

As we know, metamask will no longer inject web3.js starting Jan 13, 2020. What are the approaches we should take to stop the dependency on web3?

Also how can we test it out with the existing Metamask that is injecting web3.js as of now.

Interlock answered 4/12, 2019 at 9:19 Comment(1)
Hello and welcome to Stack Overflow. Please avoid adding details in comments, prefer an edit to your original post.Geisler
M
8

window.ethereum will still contain Web3 Provider. You can use it setup your web3 convenience library of choice such as web3.js or ethers.js. For example:

const Web3 = require('web3');
// web3 lib instance
const web3 = new Web3(window.ethereum);
// get all accounts
const accounts = await web3.eth.getAccounts();
Monosymmetric answered 27/12, 2019 at 10:5 Comment(0)
J
2
import Web3 from "web3";

let web3;
const ethEnabled = async () => {
    if (window.ethereum) {      
      web3 = new Web3(window.ethereum);
      await window.ethereum.enable();
    }
    
  }
ethEnabled();
export default web3;
Jegger answered 18/10, 2021 at 7:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.