Skip to content

Instantly share code, notes, and snippets.

@mgild
Created August 2, 2022 12:30
Show Gist options
  • Save mgild/393a075c0f11192cacbc7bf3d6298ee1 to your computer and use it in GitHub Desktop.
Save mgild/393a075c0f11192cacbc7bf3d6298ee1 to your computer and use it in GitHub Desktop.
import fetch, { Response } from "node-fetch";
async function doQuery(query: string): Promise<any> {
const response = await fetch("https://api.vybenetwork.com/v1/graphql", {
method: "POST",
headers: {
Authorization: "b65fcbef-ead9-4893-86a1-28c12e43b59f",
},
body: JSON.stringify({
query: query,
}),
});
return response.json();
}
async function getLeaseFund() {
let query = ` {
switchboard_switchboard_v2_m_events(
where: {name: {_eq: "LeaseFundEvent"}, blockTime: {_gt: "1656637200", _lt: "1659315600"}}
) {
blockTime
data
}
}
`;
let res = await doQuery(query);
console.log(JSON.stringify(res.data.switchboard_switchboard_v2_m_events));
let count = 0;
const sumWithInitial = res.data.switchboard_switchboard_v2_m_events.map(
(entry: any) => {
count += +entry.data.amount;
}
);
console.log("total: ", count);
}
getLeaseFund().then(
() => {
process.exit();
},
(err) => {
process.exit(0);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment