API on JavaScript

Hello,

I wrote the code bellow to make an api and show some Network status via js. However, I have been not able to do so. Console is showing 405, so I am sure it has to do with the parameters (or the code itself) but I am not sure how to define that with the correct notation. What am I missing?

I am very young and relatively new to coding, so any help would be appreciated. A well written example would be good as well. I am willing to learn! :slight_smile:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0"
    />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Fetch JSON</title>
  </head>
  <body>
    <script>
        const api_url = 'https://api.zilliqa.com/';
        async function getBlockchainData() {            
            const zilliqa = await fetch(api_url);
            const blockChainInfo = await zilliqa.blockchain.getBlockChainInfo();
            console.log(blockChainInfo.result);
            
        }
         getBlockchainData();
      
    </script>
  </body>
</html>

You can use JavaScript-Library with wallet ZilPay and will read this article

The issue here is that your zilliqa is not instantiated. In your await fetch(api_url), you are not fetching anything as you did not pass any parameter.

const api_url = 'https://api.zilliqa.com/';
async function getBlockchainData() {            
     const zilliqa = new Zilliqa(api_url);
     const blockChainInfo = await zilliqa.blockchain.getBlockChainInfo();
     console.log(blockChainInfo.result);
}
getBlockchainData();

This should help.

async function getBlockchainData() {            
 const zilliqa = new Zilliqa();
 const blockChainInfo = await zilliqa.blockchain.getBlockChainInfo();
 console.log(blockChainInfo.result);
}
getBlockchainData();

it is work.