Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web3 Not Defined in Window.load #10

Open
phillipgibb opened this issue Dec 11, 2018 · 0 comments
Open

Web3 Not Defined in Window.load #10

phillipgibb opened this issue Dec 11, 2018 · 0 comments

Comments

@phillipgibb
Copy link

web3 is defined in the your-app submodule
After adding my submodule which is a reactjs -bootstrap project
it attempts to obtain a handle on web3 to no avail.
Adding the web3 script to index.html does not help.
The following is printed to my console:

Non-Ethereum browser detected. You should consider trying MetaMask!

        window.addEventListener('load', async () => {
            // Modern dapp browsers...
            if (window.ethereum) {
                window.web3 = new Web3(ethereum);
                try {
                    // Request account access if needed
                    this.setState({pendingEnable: true})
                    ethereum.enable().then((res) => {
                        console.log(`Connect Result : ${res}`)
                        this.setState({web3Obj: window.web3, pendingEnable: false, acceptedEnable: true, loading: false})
                    });
                } catch (error) {
                    // User denied account access...
                    this.setState({web3Obj: null, pendingEnable: false, acceptedEnable: false, loading: false})
                }
            }
            // Legacy dapp browsers...
            else if (typeof window.web3 !== 'undefined') {
                window.web3 = new Web3(web3.currentProvider);
                this.setState({web3Obj: window.web3, pendingEnable: false, loading: false})
            }
            // Non-dapp browsers...
            else {
                console.log('Non-Ethereum browser detected. You should consider trying MetaMask!');
                this.setState({web3Obj: null, pendingEnable: false, loading: false})

            }
        });
    }```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant