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

Chrome console showing null account?? Token address is also different #31

Open
ChowdhuryRidwan opened this issue Apr 4, 2020 · 1 comment

Comments

@ChowdhuryRidwan
Copy link

ChowdhuryRidwan commented Apr 4, 2020

Problem is in the connection of metamask to the local blockchain by using its RPC address. I use the private key of the first account to get its information. But in my system the first account's actual address in ganache is: 0x4DF4F75E96D49A1b61a4Cd1800d55444bb39C761 but the address that is displayed in my chrome console is 0xED4Cd7eA80CfdDef5c78F6A02C9352124AA6D835. Also in app.js in the render function where I have to display my account I am getting account as NULL. Please do confirm why it is different. How do I wire up the actual account to app.js.

Screen Shot 2020-04-04 at 7 10 37 PM

@megancooper
Copy link

megancooper commented Aug 14, 2020

@ChowdhuryRidwan
I was able to fix this issue with the following code: (see https://ethereum.stackexchange.com/a/78987)

initWeb3: function( ) {
// Wait for loading completion to avoid race conditions with web3 injection timing.
        if (window.ethereum) {
          const web3 = new Web3(window.ethereum);
          try {
            // Request account access if needed
            window.ethereum.enable()
                .then(web3 => {
                    console.log(web3)
                    App.web3Provider = web3;
                });
          } catch (error) {
            console.error(error);
          }
        }
        // Legacy dapp browsers...
        else if (window.web3) {
          // Use Mist/MetaMask's provider.
          const web3 = window.web3;
          console.log('Injected web3 detected.');
          App.web3Provider = web3;
        }
        // Fallback to localhost; use dev console port by default...
        else {
          const provider = new Web3.providers.HttpProvider('http://127.0.0.1:7545');
          const web3 = new Web3(provider);
          console.log('No web3 instance injected, using Local web3.');
          App.web3Provider = web3;
        }
        return App.initContracts();
    },

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

2 participants