Skip to content

Instantly share code, notes, and snippets.

@sayon-bitquery
Last active June 9, 2021 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sayon-bitquery/edcf5680e61a39a06df1ff746b549392 to your computer and use it in GitHub Desktop.
Save sayon-bitquery/edcf5680e61a39a06df1ff746b549392 to your computer and use it in GitHub Desktop.
Next step, is to make a variable which would take a GraphQL query and execute it in Bitquery’s API through the endpoint.
export default function App() {
const { data, isLoading, error } = useQuery("bitcoin", () => { //launches
return fetch(endpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": "YOUR API KEY"
},
body: JSON.stringify({ query: QUERY }) // ({ QUERY })
})
.then((response) => {
if (response.status >= 400) {
throw new Error("Error fetching data");
} else {
return response.json();
}
})
.then((data) => data.data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment