简体   繁体   中英

Metamask stopping to inject web3.js

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.

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();
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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM