2
arkeo 3 weeks ago

Error in web.min.js

I am not able to get the desired output. Nothing is being printed in the table…
The following is the error I am getting in the console, which I am not able to understand…
Uncaught (in promise) TypeError: r is not a function
    at web3.min.js:1
    at n.sendAsync (web3.min.js:1)
    at l.t [as getBlockNumber] (web3.min.js:1)
    at updateBlocks (index.html:26)
    at window.onload (index.html:21)
My index.html look like the following as it is in the video : 
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Blockchain Explorer</title>
  </head>
  <body>
    <table id="blocks" width='100%'>
      <tr>
        <th>Number</th>
        <th>Hash</th>
        <th>Timestamp</th>
      </tr>

    </table>

    <script src="./web3.min.js"></script>

    <script>
      window.onload = function() {
        updateBlocks();
      };

      async function updateBlocks(){
        let web3 = new Web3(Web3.givenProvider);
        let latest = await web3.eth.getBlockNumber();

        for(var i=0; i<10; i++){
          let block = await web3.eth.getBlock(latest-i);
          printBlock(block);
        }
      }

      function printBlock(block) {
        var table = document.getElementById('blocks');
        var row = table.insertRow(-1);
        var cell1 = row.insertCell(0);
        var cell1 = row.insertCell(1);
        var cell1 = row.insertCell(2);
        cell1.innerHTML = block.number;
        cell2.innerHTML = block.hash;
        cell2.innerHTML = block.timestamp;
      }
    </script>

  </body>
</html>
  1. 2
    Jack Wu
    Jack Wu 3 weeks ago
    When you’re downloading the web3.min.js file from the github repo, please make sure under branches, you select tag and select the latest release (e.g. v1.0.0-beta.36). If you selected the “develop” branch, then you will get errors. Also make sure you have Metamask installed and you’re also running a local web server such as lite-server.

  2. 2
    arkeo 2 weeks ago
    Thanks a lot for the help!!!