const axios = require('axios');

// Declare the beacon provider URL and request parameters.
const BEACON_PROVIDER_URL = "CHAINSTACK_BEACON_URL";
const HEADER = { 'Content-Type': 'application/json' };
const BLOCK_ID = "head";

// Send the request
axios.get(`${BEACON_PROVIDER_URL}/eth/v2/beacon/blocks/${BLOCK_ID}`, { headers: HEADER })
  .then(response => {

    // Parse the response and log the result.
    try {
      const parsedJson = response.data;
      const slot = parsedJson.data.message.slot;
      const randao = parsedJson.data.message.body.randao_reveal;

      console.log(`randao value for slot ${slot} is: ${randao}`);
    } catch (error) {
      console.error(`An error occurred while parsing the response: ${error}`);
    }
  })
  .catch(error => {
    console.error(`An error occurred while fetching the data: ${error}`);
  });
$ node index
randao value for slot 5717752 is:
0x91bed944631c3178c3c3d2ba2b981b12fc68bfc22e66c7f77477416f9f46837b15ae6cd6feb4347484c83e83751c7cab0bf93e39698eb61ab38fff51727a03a04ee1fa427162fc9539e647619be88b8bb0db37f7d241883371dca99fa049a2be
const axios = require('axios');

// Declare the beacon provider URL and request parameters.
const BEACON_PROVIDER_URL = "CHAINSTACK_BEACON_URL";
const HEADER = { 'Content-Type': 'application/json' };
const BLOCK_ID = "head";

// Send the request
axios.get(`${BEACON_PROVIDER_URL}/eth/v2/beacon/blocks/${BLOCK_ID}`, { headers: HEADER })
  .then(response => {

    // Parse the response and log the result.
    try {
      const parsedJson = response.data;
      const slot = parsedJson.data.message.slot;
      const randao = parsedJson.data.message.body.randao_reveal;

      console.log(`randao value for slot ${slot} is: ${randao}`);
    } catch (error) {
      console.error(`An error occurred while parsing the response: ${error}`);
    }
  })
  .catch(error => {
    console.error(`An error occurred while fetching the data: ${error}`);
  });
$ node index
randao value for slot 5717752 is:
0x91bed944631c3178c3c3d2ba2b981b12fc68bfc22e66c7f77477416f9f46837b15ae6cd6feb4347484c83e83751c7cab0bf93e39698eb61ab38fff51727a03a04ee1fa427162fc9539e647619be88b8bb0db37f7d241883371dca99fa049a2be