January 2020
Intermediate to advanced
530 pages
11h 11m
English
We use our componentDidMount method to check if the MetaMask-injected web3provider is currently available within the browser window. This is done by checking if the window.ethereum object is available, as follows:
componentDidMount(){ var account;if (window.ethereum) {
If window.ethereum is available, we instantiate our current web3 instance so that it uses the MetaMask-injected web3 instance, like this:
if (window.ethereum) { const ethereum = window.ethereum; window.web3 = new Web3(ethereum); this.web3 = new Web3(ethereum);
Next, we ask MetaMask for permission to access the user's accounts that are available in the MetaMask wallet. This is done by requesting access through ethereum.enable(), as follows: ...
Read now
Unlock full access