dappuniversity / eth-todo-list

Blockchain Todo App Tutorial Powered by Ethereum Smart Contracts
549 stars 549 forks source link

Uncaught (in promise) Error: Invalid JSON RPC response: undefined #4

Open tanujajoshi1 opened 3 years ago

tanujajoshi1 commented 3 years ago

Screenshot from 2020-09-14 00-37-01

I am getting these error after writing my app.js. My metamask is do connecting, ganache is also open still it is breaking somewhere. Please help me. I am using Ubuntu with latest version of web3 and truffle

ghost commented 3 years ago

Same issue. But its because you're not using the exact specific versions he is, at least I assume you aren't.

I use the below code for connecting up to metamask, note that I comment out the tx.

loadWeb3: async () => {

        // Modern dapp browsers...
        if (window.ethereum) {

            window.web3 = new Web3(ethereum);
            try {
                // Request account access if needed
                await ethereum.enable();
                // Acccounts now exposed
                //web3.eth.sendTransaction({/* ... */});
            } catch (error) {
                // User denied account access...
            }
        }
        // Legacy dapp browsers...
        else if (window.web3) {
            window.web3 = new Web3(web3.currentProvider);
            // Acccounts always exposed
            //web3.eth.sendTransaction({/* ... */});
        }
        // Non-dapp browsers...
        else {
            console.log('Non-Ethereum browser detected. You should consider trying MetaMask!');
        }

        console.log("done loading web3");

    },

For your load account you will need a different way to get an account

loadAccount: async () =>{

        App.account = web3.eth.defaultAccount;
        console.log(App.account);

    },