2

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

Questioner
  • 2,670
  • 2
  • 33
  • 62

1 Answers1

2

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>
Richard Horrocks
  • 37,835
  • 13
  • 87
  • 144
  • Thank you, now I do not receive error, However, I cannot see signature value that I explain the question here: https://ethereum.stackexchange.com/questions/54883/how-to-see-output-of-web3-personal-sign-in-browser Thanks – Questioner Jul 22 '18 at 18:52