This project is an Automated Telegram Bot that listens to blockchain events on any EVM chain. Specifically, it is designed to listen to NFT transfers from a specified NFT smart contract.
It can be expanded to listen for:
- NFT minting events
- Token transfers
- Other blockchain events
- Listens to NFT transfers from a smart contract on an EVM chain.
- Sends real-time updates to a Telegram bot whenever an NFT is transferred.
- Supports additional features for listening to other types of events, such as token transfers or NFT minting.
Before running the project, you need to have the following installed:
- Node.js (Recommended version:
v16+
) - npm (comes with Node.js)
- ngrok (for public URL tunneling)
- Telegram Bot API Token
First, clone this repository to your local machine:
git clone <repository-url>
cd telegram-nft-bot
Run the following command to install the required packages:
npm install
Create a .env
file in the root directory of the project and add the following variables:
TELEGRAM_BOT_TOKEN=your-telegram-bot-token
WEBHOOK_SECRET=your-webhook-secret (optional)
EVM_PROVIDER_URL=https://mainnet.infura.io/v3/your-infura-project-id (or your preferred provider)
NFT_SMART_CONTRACT_ADDRESS=0xYourNFTSmartContractAddress
- TELEGRAM_BOT_TOKEN: Create a Telegram bot by talking to @BotFather and get the token.
- WEBHOOK_SECRET: (Optional) Secret used for securing the webhook.
- EVM_PROVIDER_URL: URL for connecting to the Ethereum (or other EVM) blockchain (e.g., Infura or Alchemy).
- NFT_SMART_CONTRACT_ADDRESS: The address of the NFT smart contract you want to monitor.
Open a terminal window and navigate to the project directory. Start the backend server using:
npm run dev
This will start the server with nodemon
to watch for any code changes and restart the server automatically.
Run ngrok
to expose your local server:
ngrok http 5001
This will give you a publicly accessible URL, like http://<random-string>.ngrok.io
, which you will use to configure the webhook.
Now, open your Telegram bot and send /start
to it. Your bot should respond with a message. The bot will listen for NFT transfer events and send notifications when one occurs.
To make the bot work continuously, you can deploy it to a cloud provider like Heroku, AWS, or DigitalOcean. You’ll need to set the environment variables there and expose your webhook URL using a service like ngrok or use the cloud provider’s equivalent solution.
- NFT Transfer Monitoring: The bot listens for NFT transfers using the event logs of an NFT smart contract. When an NFT is transferred, the bot captures the relevant details:
- From Address: The sender's address
- To Address: The recipient's address
- Token Name and ID: The NFT's name and ID
- Transaction Hash: The hash of the transaction
- Telegram Notification: The bot sends these details as a message to your Telegram bot for real-time updates.
The bot will log details like:
From address: 0x1234...5678, To address: 0x8765...4321, Token Item: MyNFT #1234, Transaction Hash: 0xabcde...12345
You can customize the bot to listen to additional events, such as NFT minting or token transfers, by modifying the code in webhook.js
.
To contribute or modify the bot, follow these steps:
- Fork the repository.
- Clone your fork to your local machine.
- Create a new branch for your changes.
- Implement the changes.
- Commit the changes and push to your fork.
- Submit a pull request to the main repository.
Feel free to open issues, fork the repository, and submit pull requests. All contributions are welcome!
This project is licensed under the MIT License - see the LICENSE.md file for details.
Note: Be sure to configure and use your own API keys and secrets for production deployments.
Check Out My Personal Bored Ape Yacht Club Telegram Bot
- I also have a personal Telegram bot that listens to events from the Bored Ape Yacht Club (BAYC). You can check it out and join the community!
👉 Link: https://t.me/BoredApeYachtClubNFTBot
👉 Username: @BoredApeYachtClubNFTBot