Build a Bot with ZettaBlock GraphQL API
Kamal Nayan
Posted on January 1, 2023
- I created a SQL on the ZettaBlock platform.
- Creating a Graphql query
- Started with the telegram bot.
The left side highlights the data sources and tables available.
So I started by setting up a new telegram Bot by going to BotFather and following some simple commands mentioned in the below ss.
After that I explored the zettablock space for an hour of how things work.
So I executed the steps in this order
- Made a Data Query
- I created an SQL Query to fetch solana tokens on the mainnet.
SELECT
"name",
"symbol",
"decimals",
"token_authority",
"supply",
"type",
"address"
FROM
solana_mainnet.token_metadata
LIMIT
20
- After this I created my API to query the data.
Indexed the data by selecting the name, symbol and supply field
- Got the API key and now opened VS Code.
Initialised the project by installing node-telegram-bot api package and dotenv
https://github.com/yagop/node-telegram-bot-api
- Created an index.js script for the bot to fetch the solana tokens metadata Live.
Wrote a simple graphql query to query the data
data: {
query: `
{
records(symbol:
"${symbol}", limit: 1 )
{
name
symbol
address
supply
type
token_authority
}
}
`,
},
and then passed it to the bot as replymsg for when user passes the symbol of the token as an argument.
const replyMsg = `
🪙 SOL Token Data:
- Solana Mainnet Token Address: ${data.address}
- Name: ${data.name}
- Token: ${data.symbol}
`
bot.sendMessage(chatId, replyMsg)
- Opened the telegram bot and It worked ! hurray and that's how an awesome bot was made.
💖 💪 🙅 🚩
Kamal Nayan
Posted on January 1, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.