1

This is my simple html source code for my website.

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta name="viewpoint" content="width=device-width, initial-scale=1.0">
   <meta http-equiv="X-UA-Compatible" content="ie=edge">
   <title>ABI test</title>
   <script src="/Users/Huiwon/node_moduels/web3/dist/web3.min.js"></script>
</head>

<body>
  <div class="container">
    <h1>Successful!</h1>
  </div>
  <script src="http://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
  <script>
  if (typeof web3 !== 'undefined') {
    web3 = new Web3(web3.currentProvider);
  } 
  else{
    web3 = new Web3(new 
    Web3.providers.HttpProvider("http://localhost:8545"));
  }
  let accounts = web3.eth.accounts
  accounts.map(item => {console.log(item)});
  </script>
</body>
</html>

And i got error message : Uncaught ReferenceError: Web3 is not defined at SimpleStorage2.html:21 in the console of website

line 21 is

Web3.providers.HttpProvider("http://localhost:8545"));

i already installed Web3 by npm installation

i also have error message :

'web3.min.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND'

please help me to solve problem Thank you

1
  • 2
    Check your browser console, likely web3.min.js failed to load.
    – Ismael
    Feb 7, 2019 at 5:04

2 Answers 2

0

Look at the network section in your browser console and check for errors where it's supposed to be loading your external JavaScript.

At a minimum it'll be failing because you have a typo in node_modules, but it may also be failing for other reasons.

2
  • i don't have much knowledge about network and blockchian. So can you explain more about 'loading your external JavaScirpt' In addition i have more error ' web3.min.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND'
    – jhwon1015
    Feb 8, 2019 at 4:25
  • Simply, you have a URL for your web3.min.js in your HTML and that URL is wrong, so your browser can't load it. For simplicity, try copying web3.min.js to the same directory as your HTML file and load it with <script src="web3.min.js"></script> Feb 8, 2019 at 22:43
0

You are NOT able to load external scripts directly from node_modules directory. To make it work you should copy the web3.min.js into your local workspace(may stay at the same level with the html code) and run it.

Your Answer

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

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