I want to create an interface to interact with my smart contract. I have got an example from the following link. Counter

Before implementing my contract, I have tried to use the given example.But it throws an error - " Unable to find web3. Please run MetaMask (or something else that injects web ".But I am able to run the dApp from their website - Counter

  • How exactly are you testing the app? Using an HTML page saved on your computer? Commented Oct 15, 2018 at 8:58
  • If you are able to run their dApp correctly (you see the messages "found injected web3" and "getCount call executed correctly"), it means you have Metamask installed and you are log in. Double check that just in case. Are you including the web3 library in the correct way? Do you see any errors in the browser console (Press F12 and go to Console if you are using Google Chrome) when you import it or run your code?
    – Patricio
    Commented Oct 15, 2018 at 8:58
  • @ShawnTabrizi I have copied the available code and saved as html page on my PC.
    – Pt.AR
    Commented Oct 15, 2018 at 9:01
  • @Patricio yes I have metamask account and i am logged in. I am not sure about the web3 library.I didn't install web3 on my PC.But I am able to use web3 on geth.So I am not sure about the location of web3. Do I have to install web3 separately?
    – Pt.AR
    Commented Oct 15, 2018 at 10:17
  • @Patricio I have downloaded web3 and stored in a location.Then given the location as <script src=".\dist\web3.min.js"></script>.Now it is showing found web3. But not able to access the functions.Stuck at somewhere.I will check the issue and add my doubts as next comment.Thank you.
    – Pt.AR
    Commented Oct 15, 2018 at 12:18

1 Answer 1


Unfortunately you cannot use Metamask on local webpages (just opening a file on your computer). It is explicitly restricted:

🌐 Http(s) - Web Server Required

Due to browser security restrictions, we can't communicate with dapps running on file://. Please use a local server for development.

You will need to publish your code to a local server to test MetaMask functionality.

Visual Studio Code has a great plugin to easily do just this.

  • Metamask is used as web3 provider,right?So is there any other tool serve as web3 provider?Whether I can use geth? I have deployed the contract using geth console.
    – Pt.AR
    Commented Oct 15, 2018 at 9:10
  • 1
    Yes you could use something like geth, which has an unlocked account, and enough test/real ether to complete a transaction. You would add a line that looks like: web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); as shown here. Commented Oct 15, 2018 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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