Prerequisites
Prerequisites
You will need a Chainstack account and an Ethereum node to follow this recipe.
Environment setup
Environment setup
1
Install node.js in case it is not installed yet.
2
Create a new directory for your project.
3
Initialize an npm project:
4
Install the axios package:
Import the package and set up the request details
Import the package and set up the request details
Create a new file
index.js
, import the axios library, and initialize the parameters required for this request.This script will send a GET
request to the Ethereum Beacon chain.Paste your Beacon Chainstack node URL in the BEACON_PROVIDER_URL
const.Also, set up the request parameters. The BLOCK_ID
constant identifies which block to query.index.js
Send the request
Send the request
The body of the script is the code to send the request.This part sends a request to the Beacon provider, parses the response, and prints a statement in the console.
index.js
Slot and randao
Slot and randao
This script isolates the
slot,
and randao
fields of the object returned.They are held in the respective constants and you can wrap this code in a function to return those values and do more processing.index.js
Run the script
Run the script
Now you only need to save the file and run it with:
node index
This command will run the program and display the response.