This is a JavaScript app that extracts data from a contract using a BSC Scan API and Public RPC Nodes.
This code is written in JavaScript and uses various libraries to interact with the Binance Smart Chain (BSC) network and extract data from a smart contract.
The code starts by importing the required libraries: ethers, axios, fs, Big, Web3, BN, csv, and json2csv. It then sets some parameters such as the start and end blocks, the number of blocks per transaction, the filter criteria, and the provider URLs.
The extractDataFromAPI()
function is the main function that extracts the data from the BSC network. It uses the axios
library to send an HTTP request to the BSC network and fetch the transaction data from a smart contract. The API key is passed in the query string to authenticate the request.
The getData()
function is used to retrieve the data from the API. If the data is null or undefined, the function retries the API call until it gets the data.
The function then filters the data based on the filterBy
criteria and maps it to an array of objects that contain the transaction hash, value, timestamp, block number, block hash, and string date. The value is calculated using the getValueByHash()
function, which extracts the value from the transaction receipt.
The function then filters the array of objects based on the current date and writes the data to a JSON file. If the next date is found, the function updates the current date and writes the data to a new JSON file.
The getValueByHash()
function uses the getTransactionReceipt()
function to retrieve the transaction receipt from the BSC network and calculate the total claim value. The function uses the BN
library to handle large numbers and convert them to floating-point values.
The writeJSON()
function writes the JSON data to a file with the name based on the current date.
The formatDate()
function formats the timestamp to a string in the format YYYY-MM-DD-HH
.
Finally, the setInterval()
function calls the extractDataFromAPI()
function every 5000 milliseconds to extract data continuously from the BSC network until the end block is reached.