PHPH1 elephant logo

Description

  • Gets a list of the latest beacon chain headers and their related information.

    There may be more information in the PHPH1 Class Documentation.

Parameters

  • No Parameters Required

Returns

  • Object:
  • beacon-chain-header - Object:
    • difficulty - String:
      FIXME
    • epoch - Number:
      Epoch number
    • extraData - String:
      FIXME
    • gasLimit - String:
      FIXME
    • gasUsed - String:
      FIXME
    • hash - String:
      FIXME
    • logsBloom - String:
      FIXME
    • miner - String:
      FIXME
    • mixHash - String:
      FIXME
    • nonce - String:
      FIXME
    • number - String:
      FIXME
    • parentHash - String:
      FIXME
    • receiptsRoot - String:
      FIXME
    • sha3Uncles - String:
      FIXME
    • shardID - Number:
      FIXME
    • stateRoot - String:
      FIXME
    • timestamp - String:
      FIXME
    • transactionsRoot - String:
      FIXME
    • viewID - Number:
      View ID
  • shard-chain-header - Object:
    • difficulty - String:
      FIXME
    • epoch - Number:
      Epoch number
    • extraData - String:
      FIXME
    • gasLimit - String:
      FIXME
    • gasUsed - String:
      FIXME
    • hash - String:
      FIXME
    • logsBloom - String:
      FIXME
    • miner - String:
      FIXME
    • mixHash - String:
      FIXME
    • nonce - String:
      FIXME
    • number - String:
      FIXME
    • parentHash - String:
      FIXME
    • receiptsRoot - String:
      FIXME
    • sha3Uncles - String:
      FIXME
    • shardID - Number:
      FIXME
    • stateRoot - String:
      FIXME
    • timestamp - String:
      FIXME
    • transactionsRoot - String:
      FIXME
    • viewID - Number:
      View ID
{"jsonrpc":"2.0","id":1,"method":"hmyv2_getLatestChainHeaders","params":[]}			

<script>
// In a production environment this function should probably be expanded with response and error checks etc.
async function getHMYV2Data(){
	// This URL is for mainnet shard 0
  let response = await fetch('https://a.api.s0.t.hmny.io/', {
    method: "POST",
    body: '{"jsonrpc":"2.0","id":1,"method":"hmyv2_getLatestChainHeaders","params":[]}',
    headers: { "Content-type": "application/json" }
  });

  let mydata = await response.json();

  // Check the console for output
  console.log("method data:" + JSON.stringify(mydata));
  // What you do with the returned data after this is up to you
}

// Run the getHMYV2Data function
getHMYV2Data();
</script>
	

<script>
// You can reuse this function with multiple methods
// In a production environment this function should probably be expanded with response and error checks etc.
async function getPHPH1Data(url, formdata){
  let response = await fetch(url, {
    method: "POST",
    body: formdata,
    headers: { "Content-type": "application/x-www-form-urlencoded" }
  });

  let mydata = await response.json();

  // Check the console for output
  console.log("method data:" + JSON.stringify(mydata));
  // What you do with the returned data after this is up to you
}

// This is the call URL. It will always require the method being used to be sent in the URL
// Depending on your setup, you may need to adjust the path to this url
// For example: /your/path/to/phph1/phph1_call.php?method=hmyv2_getLatestChainHeaders
var url = "phph1_call.php?method=hmyv2_getLatestChainHeaders";

// The formdata variable is always set
// Even if there is no form data we need the dorequest sent
var formdata = "dorequest=1";

// Run the getPHPH1Data function
getPHPH1Data(url, formdata);
</script>