0

I have Metamask connected to the local Ganache network, but I am getting the "No web3? You should consider trying MetaMask!" message, so apparently Metamask isn't being used. How would I get it to use Metamask?

Metamask Settings

Checking Metamask

  • "when it's connected to local network" Are you implying that web3 is defined when you're connected to another network? – smarx Apr 24 '18 at 16:40
  • web3 is undefined when it's currently connected to the local 7545 network. – Rychard Apr 24 '18 at 17:13
  • Again, are you implying that it is defined when connected to a different network? – smarx Apr 24 '18 at 17:16
  • I don't know if it's defined when it's connected to a different network. I am deploying my smart contracts on this local 7545 network and I would like Metamask to work when it's connected to it. Metamask being defined when it's connected to a different network doesn't solve my issue with this current network. – Rychard Apr 24 '18 at 17:22
  • But it changes the question you're asking. If you asked someone "Why doesn't my car start when it's cold outside?" they wouldn't consider options like "there's no battery in it," because that would equally be a problem in warm weather. – smarx Apr 24 '18 at 17:24
0

Are you running your 'html' file as 'http://' or 'file://' ? Because, this won't work in file:// method.

Just verified it locally. I've ganache running on HTTP://127.0.0.1:8545 and used node js (app.js) and index.html files.

index.html

<script type="text/javascript" src="D:\TestEth\capestoneEthILP\html\js\web3.js"></script>
<script type="text/javascript">
    var web3js;
    if(typeof web3 != 'undefined'){
        web3js = new Web3(web3.currentProvider);
        console.log("found web3?")
    }else{
        console.log("No Web3!");
        web3js = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"))
    }
</script>

app.js

const express = require('express')
const app = express()
var path = require('path');

// viewed at http://localhost:8080
app.get('/', function(req, res) {
    res.sendFile(path.join(__dirname + '/index.html'));
});
app.listen(3000, () => console.log('Example app listening on port 3000!'));

Open Node js..

C:\Users\mk\Desktop>node app.js
Example app listening on port 3000!

And the console output was like this...

Not allowed to load local resource: file:///D:/TestEth/capestoneEthILP/html/js/web3.js
(index):6 found web3?
(index):1 Error in event handler for (unknown): TypeError: Cannot read property 'state' of null
    at CSRecorder.onQueryStateCompleted (chrome-extension://cplklnmnlbnpmjogncfgfijoopmnlemp/content_scripts/recorder.js:106:18)
inpage.js:9 MetaMask: web3 will be deprecated in the near future in favor of the ethereumProvider 
https://github.com/MetaMask/faq/blob/master/detecting_metamask.md#web3-deprecation
get @ inpage.js:9
(anonymous) @ VM82:1
ContentLoader.js:28 failed to get content script
  • It's running on http. That's not the issue. – Rychard Apr 24 '18 at 17:15
0

Resolved:

Metamask doesn't only works within the browser, so include all the contract calling logic in the frontend code.

Answer provided by smarx in the comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.