2

I'm trying to integrate web3 into a website which uses Django.

This snippet of code is not working

  <script type="text/javascript">
      document.getElementById("Mining").innerText = "Test";
      var Web3 = require('web3');
      var web3 = new Web3();
      web3.setProvider(new web3.providers.HttpProvider("http://146.169.45.149:9002"));
      var mining = web3.eth.mining;
  </script>
</body>

When I place the line document.getElementById("Mining").innerText = "Test"; under the var web3 = require('web3'); it stops working, so I'm guessing the problem should be there.

I've included both scripts for web3

<!-- web3 scripts -->
<script type = "text/javascript" src="/static/poll/web3-light.js"></script>
<script type = "text/javascript" src="/static/poll/bignumber.js"></script>

Thanks.

1

This is hard to debug without seeing your actual code. If it's falling over on the require line it's most likely failing to load the web3 javascript file, or loading it after you've placed your script. Look in the developer console of your browser and see if it's telling you anything, and also whether it's making the network requests for the JavaScript files and whether they're being found. Django could be serving them from there, but only if you've set the static/ path correctly and actually put the files there.

  • I looked in the developer console but both web3 files are being found so that shouldn't be the problem. What else could make the require statement fail? – punddalinni May 8 '16 at 10:59
  • Aren't you getting any errors reported at all? – Edmund Edgar May 8 '16 at 11:12
  • I think you want bignumber before web3-light.js, but you should be getting errors reported. – Edmund Edgar May 8 '16 at 11:28
  • I switched them and it seems to be working now. And you were also right, there were errors in the developer console but I wasn't seeing them. Thanks! – punddalinni May 8 '16 at 14:22

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.