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.
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
仍将包含 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;