1

What is problem of this simple html / JavaScript / ethreumjs / web3.js code?

    <!doctype html>

    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>EthereumJS - Browser Example</title>
    </head>

    <body>
      <script src="https://rawgit.com/ethereumjs/browser-builds/master/dist/ethereumjs-abi/ethereumjs-abi-0.6.5.js"></script> 
  <script src="https://rawgit.com/ethereum/web3.js/develop/dist/web3.js"></script> 
  <script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js"></script> 

      <script>

      var abi = new ethereumjs.ABI()
      var Web3 
      web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

      </script>
    </body>
    </html>

When I run this code I receive the following error in Console of browser in line 17 of this code (i.e. web3 = new Web3(new Web3.providers...) :

Uncaught TypeError: Cannot read property 'providers' of undefined at test.html:17

Note: Please note that I cannot use Web3 = require("web3") , because I receive following error:

Uncaught ReferenceError: require is not defined

1

Note: Please note that I cannot use Web3 = require("web3") , because I receive following error:

As per the documentation for including web3 as a browser module (which you're already doing for the ABI code):

<script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js"></script>

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.