'Reference error window not defined error in Web3
Here is my code:
import Web3 from './web3';
if (window.ethereum) {
window.web3 = new Web3(ethereum);
try {
// Request account access if needed
ethereum.enable();
} catch (error) {
// User denied account access...
}
} else if (window.web3) {
// Legacy dapp browsers...
window.web3 = new Web3(web3.currentProvider);
} else {
// Non-dapp browsers...
console.error('Non-Ethereum browser detected. You should consider trying MetaMask!');
}
export default window.web3;
I am getting the error as:
Server Error Reference error Window not defined
Getting error at line:
window.web3 = new Web3(ethereum);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|