Metamask 停止注入 web3.js

Metamask stopping to inject web3.js

据我们所知,从 2020 年 1 月 13 日开始,metamask 将不再注入 web3.js。我们应该采取哪些方法来停止对 web3 的依赖?

此外,我们如何使用目前正在注入 web3.js 的现有 Metamask 对其进行测试。

window.ethereum 仍将包含 Web3 提供程序。您可以使用它来设置您选择的 web3 便利库,例如 web3.js 或 ethers.js。例如:

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;