Skip to content

Instantly share code, notes, and snippets.

@sayon-bitquery
sayon-bitquery / index.js
Created June 9, 2021 11:16
This is the index.js file where we wrap the <App /> with <QueryClientProvider />
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { QueryClient, QueryClientProvider } from "react-query";
const client = new QueryClient();
ReactDOM.render(
@sayon-bitquery
sayon-bitquery / app.js
Last active June 9, 2021 11:30
Now, in the src/App.js file, import { useQuery } from ‘react-query’ and make a variable as the endpoint which saves the API endpoint of BitQuery’s GraphQL API i.e. https://graphql/bitquery.io/
import React from "react";
import { useQuery } from "react-query";
const endpoint = "https://graphql.bitquery.io/";
const QUERY = `
{
bitcoin {
blocks(options: {limit: 2}){
height
blockHash
@sayon-bitquery
sayon-bitquery / app.js
Last active June 9, 2021 11:37
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 })
})
@sayon-bitquery
sayon-bitquery / app.js
Last active June 9, 2021 11:39
In the App() of the src/App.js we’ll then make a React component that will have the data from the useQuery function which in turn uses the fetch API and also, we need to specify a header that includes the content type of the data that we want back from our request.
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 })
@sayon-bitquery
sayon-bitquery / app.js
Created June 9, 2021 11:41
Finally, display the data as shown
return (
<div>
<h1>BitQuery & React</h1>
<ul>
{data.bitcoin.blocks.map((query) => (
<li key={query.height}>{query.blockHash}</li>
))}
</ul>
</div>
);
@sayon-bitquery
sayon-bitquery / main.py
Created June 10, 2021 15:16
Importing necessary libraries and adding the API keys
import os
import telebot
import requests
from decouple import config
KEY = config('YOUR TELEGRAM BOT API KEY')
API_KEY = config('YOUR BITQUERY.IO API KEY')
@sayon-bitquery
sayon-bitquery / main.py
Created June 10, 2021 15:22
Telegram Bot instance
# Telegram Bot instance
bot = telebot.TeleBot(KEY)
@sayon-bitquery
sayon-bitquery / main.py
Created June 10, 2021 15:22
Telegram Bot function which communicate with the user
def greeting(message):
request = message.text.split()
if len(request) < 2 and request[0].lower() in "hello" or request[0].lower() in "hi" or request[0].lower() in "hey":
return True
else:
return False
def updated_price(message):
request = message.text.split()
if len(request) == 2 and request[0].lower() in "get" and request[1].lower() in "price":
@sayon-bitquery
sayon-bitquery / main.py
Created June 10, 2021 15:23
Telegram bot message handlers
@bot.message_handler(func=greeting)
def send_message(message):
bot.send_message(message.chat.id, "Hey! Glad to see your. I am Bitquery Updated Coin Price Bot. Please type GET PRICE to see the latest Ethereum blockchain price.")
@bot.message_handler(func=updated_price)
def send_updated_price(message):
bot.send_message(message.chat.id, str(quotePrice))
@bot.message_handler(func=thanks)
def send_thank_you(message):
@sayon-bitquery
sayon-bitquery / main.py
Created June 10, 2021 15:24
Function which makes the Telegram bot run
bot.polling()