Build a Bot with ZettaBlock GraphQL API

kamalthedev

Kamal Nayan

Posted on January 1, 2023

Build a Bot with ZettaBlock GraphQL API
  1. I created a SQL on the ZettaBlock platform.
  2. Creating a Graphql query
  3. Started with the telegram bot.

The left side highlights the data sources and tables available.

data sources and tables

So I started by setting up a new telegram Bot by going to BotFather and following some simple commands mentioned in the below ss.

tele bot

After that I explored the zettablock space for an hour of how things work.

So I executed the steps in this order

  1. Made a Data Query

data query

  1. 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 
Enter fullscreen mode Exit fullscreen mode
  1. After this I created my API to query the data.

Indexed the data by selecting the name, symbol and supply field

Indexing the data

  1. 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

  1. 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
                    }
                }
            `,
        },
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode
  1. Opened the telegram bot and It worked ! hurray and that's how an awesome bot was made.

Final work

💖 💪 🙅 🚩
kamalthedev
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.

Related