5
arkeo

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>

Answers

  1. 5
    Jack Wu
    Jack Wu
    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. 5
    arkeo
    Thanks a lot for the help!!!

  3. 5
    Bruce Taylor
    Having problems with with the wed3.min.js file. I have the 1.0.0-beta.36 non develop file ; metamask is on but I’m getting an error on local host.

    localhost/:8 The key “with” is not recognized and ignored.
    localhost/:8 The key “inital-scale” is not recognized and ignored.
    2localhost/:23 GET http://localhost:3000/wed3.min.js net::ERR_ABORTED 404 (Not Found)
    (index):30 Uncaught (in promise) ReferenceError: wed3 is not defined
        at updateBlock ((index):30)
        at window.onload ((index):26)

  4. 5
    Bruce Taylor
    index.html 

    DOCTYPE html>
    <html>

    <head>
    <meta charset=”UTF-8″>
    <meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
    <title>Blockchain Explorer</title>
    <meta name=”viewport” content=”with=device-width, inital-scale=1″>

    </head>
    <body>
    <table id=’blocks’ width=’100%’>
    <tr>
    <th>Number</th>
    <th>Hash</th>
    <th>Timestamp</th>
    </tr>
    </table>

    <script src=”./wed3.min.js”></script>
    <script>
    window.onload = function() {
    updateBlock();
    };

    async function updateBlock(){
    let web3 = new wed3(Wdb3.givenProvider);
    let latest = await web3.eth.getBlockNumber();
    console.log(latest);

    }

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

  5. 5
    Bruce Taylor
    web3.min.js

    <!DOCTYPE html>
    <html lang=”en”>
      <head>
        <meta charset=”utf-8″>
      <link rel=”dns-prefetch” href=”https://github.githubassets.com”>
      <link rel=”dns-prefetch” href=”https://avatars0.githubusercontent.com”>
      <link rel=”dns-prefetch” href=”https://avatars1.githubusercontent.com”>
      <link rel=”dns-prefetch” href=”https://avatars2.githubusercontent.com”>
      <link rel=”dns-prefetch” href=”https://avatars3.githubusercontent.com”>
      <link rel=”dns-prefetch” href=”https://github-cloud.s3.amazonaws.com”>
      <link rel=”dns-prefetch” href=”https://user-images.githubusercontent.com/”>

      <link crossorigin=”anonymous” media=”all” integrity=”sha512-3+HOqCwtQal5hOJQ+mdxiq5zmGOTjF6RhjDsPLxbKDYgGlLFeCwzoIanb7j5IiCuXKUqyC2q8FdkC4nmx2P2rA==” rel=”stylesheet” href=”https://github.githubassets.com/assets/frameworks-a2fba223d5af91496cac70d4ec3624df.css” />
      
        <link crossorigin=”anonymous” media=”all” integrity=”sha512-JmfCUdoTahB1346JNvI4oX/6936qZfC3HtwRe92QE31J0N+Apkfqj8R5sk3LnWmPgOuNt55WxblcrL0zEGOM3A==” rel=”stylesheet” href=”https://github.githubassets.com/assets/github-1035002ffeacc4c50a87d1d62462483e.css” />
        
        
        
        

      <meta name=”viewport” content=”width=device-width”>
      
      <title>web3.js/web3.min.js at v1.0.0-beta.36 · ethereum/web3.js</title>
        <meta name=”description” content=”Ethereum JavaScript API. Contribute to ethereum/web3.js development by creating an account on GitHub.”>
        <link rel=”search” type=”application/opensearchdescription+xml” href=”/opensearch.xml” title=”GitHub”>
      <link rel=”fluid-icon” href=”https://github.com/fluidicon.png” title=”GitHub”>
      <meta property=”fb:app_id” content=”1401488693436528″>

        <meta name=”twitter:image:src” content=”https://repository-images.githubusercontent.com/24655114/c71c5800-6a8c-11e9-9117-8ec357c9f69e” /><meta name=”twitter:site” content=”@github” /><meta name=”twitter:card” content=”summary_large_image” /><meta name=”twitter:title” content=”ethereum/web3.js” /><meta name=”twitter:description” content=”Ethereum JavaScript API. Contribute to ethereum/web3.js development by creating an account on GitHub.” />
        <meta property=”og:image” content=”https://repository-images.githubusercontent.com/24655114/c71c5800-6a8c-11e9-9117-8ec357c9f69e” /><meta property=”og:site_name” content=”GitHub” /><meta property=”og:type” content=”object” /><meta property=”og:title” content=”ethereum/web3.js” /><meta property=”og:url” content=”https://github.com/ethereum/web3.js” /><meta property=”og:description” content=”Ethereum JavaScript API. Contribute to ethereum/web3.js development by creating an account on GitHub.” />

      <link rel=”assets” href=”https://github.githubassets.com/”>
      <link rel=”web-socket” href=”wss://live.github.com/_sockets/VjI6Mzk3MDA1NTA5OmIzYWE1MzRjNzYzODkyYmNlZWFlNzEzMGMwN2FjZDc4ZWFlNzY0MjNlMWJkMjBlYWZlYzkyZjM4ZDFmZGRjNDc=–bac9901e38c8578f423cac5926b2ee6144135661″>
      <meta name=”pjax-timeout” content=”1000″>
      <link rel=”sudo-modal” href=”/sessions/sudo_modal”>
      <meta name=”request-id” content=”8481:250C:81FBB2:E9CE74:5CD635C1″ data-pjax-transient>