├── .env.example
├── .gitignore
├── LICENSE
├── README.md
├── index.js
└── package.json
/.env.example:
--------------------------------------------------------------------------------
1 | BOT_TOKEN=
2 | MONGODB_URI=
3 | STICKER=CAACAgIAAxkBAAMZYlU56tK5gK3DU7pcO2mFl8-UHNwAAgQAAxZuTBITbnjY-nVk3SME
4 | ETH_API=https://rpc.ankr.com/eth
5 | BNB_API=https://bsc-dataseed.binance.org
6 | MATIC_API=https://polygon-rpc.com
7 | AVAX_API=https://avalanche.public-rpc.com
8 | FTM_API=https://rpc.ftm.tools
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | package-lock.json
2 | /node_modules
3 | .env
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 SmartMainnet
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Crypto Balance Checker Bot
9 |
10 |
11 |
12 | This is a Telegram bot for checking the balances of crypto wallets
13 |
14 |
15 |
16 | It checks the balance of addresses in blockchains (Ethereum, Binance Smart Chain, Polygon, Avalanche, Fantom)
17 |
18 |
19 |
20 |
21 |
22 |
23 | ## 🚀 Getting Started
24 |
25 | ### Setting up Environment variables
26 |
27 | - Rename the `.env.example` file to `.env`
28 |
29 | - Add Telegram bot token to `BOT_TOKEN` ( get token [here](https://t.me/BotFather) )
30 |
31 | - Add MongoDB URI to `MONGODB_URI` ( learn more [here](https://www.mongodb.com/docs/drivers/node/current/fundamentals/connection/connect) )
32 |
33 | ### Installing dependencies
34 |
35 | ```
36 | npm install
37 | ```
38 |
39 | ### Run the project
40 |
41 | ```
42 | npm start
43 | ```
44 |
45 | ## 📝 License
46 |
47 | Licensed under the [MIT License](./LICENSE).
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | import 'dotenv/config'
2 | import { MongoClient } from 'mongodb'
3 | import TelegramApi from 'node-telegram-bot-api'
4 | import Web3 from 'web3'
5 |
6 | const { BOT_TOKEN, MONGODB_URI, STICKER, ETH_API, BNB_API, MATIC_API, AVAX_API, FTM_API } = process.env
7 |
8 | const client = new MongoClient(MONGODB_URI)
9 |
10 | client.connect()
11 |
12 | const db = client.db('crypto-balance-checker-bot')
13 | const users = db.collection('users')
14 |
15 | const ethWeb3 = new Web3(ETH_API)
16 | const bnbWeb3 = new Web3(BNB_API)
17 | const maticWeb3 = new Web3(MATIC_API)
18 | const avaxWeb3 = new Web3(AVAX_API)
19 | const ftmWeb3 = new Web3(FTM_API)
20 |
21 | const bot = new TelegramApi(BOT_TOKEN, { polling: true })
22 |
23 | bot.setMyCommands([
24 | { command: '/start', description: 'Start Bot' },
25 | { command: '/help', description: 'Help Info' }
26 | ])
27 |
28 | bot.on('message', async msg => {
29 | const text = msg.text
30 | const chatId = msg.chat.id
31 | const language = msg.from.language_code
32 |
33 | try {
34 | if (text === '/start') {
35 | await bot.sendSticker(chatId, STICKER)
36 | if (language === 'ru') {
37 | await bot.sendMessage(chatId,
38 | `👋🏻 Привет ${msg.from.first_name}${(msg.from.last_name === undefined) ? '': ` ${msg.from.last_name}`}!\n` +
39 | '🔎 Это бот для проверки балансов криптокошельков.\n' +
40 | '👨🏻💻 Автор: @SmartMainnet'
41 | )
42 |
43 | await bot.sendMessage(chatId,
44 | 'Отправьте адрес кошелька,\n' +
45 | 'баланс которого вы хотите проверить.\n' +
46 | 'Пример: 0xb85eaf59e6dc69ac7b6d92c6c24e1a83b582b293'
47 | )
48 | } else {
49 | await bot.sendMessage(chatId,
50 | `👋🏻 Hello ${msg.from.first_name}${(msg.from.last_name === undefined) ? '': ` ${msg.from.last_name}`}!\n` +
51 | '🔎 This is a Crypto Balance Checker Bot.\n' +
52 | '👨🏻💻 Author: @SmartMainnet'
53 | )
54 |
55 | await bot.sendMessage(chatId,
56 | 'Send the address of the wallet\n' +
57 | 'whose balance you want to check.\n' +
58 | 'Example: 0xb85eaf59e6dc69ac7b6d92c6c24e1a83b582b293'
59 | )
60 | }
61 |
62 | await users.findOne({ id: chatId }).then(async res => {
63 | if (!res) {
64 | await users.insertOne({
65 | id: chatId,
66 | username: msg.from.username,
67 | first_name: msg.from.first_name,
68 | last_name: msg.from.last_name,
69 | start_date: new Date()
70 | })
71 | }
72 | })
73 | } else if (text === '/help') {
74 | if (language === 'ru') {
75 | await bot.sendMessage(chatId,
76 | 'Отправьте адрес кошелька,\n' +
77 | 'баланс которого вы хотите проверить.\n' +
78 | 'Пример: 0xb85eaf59e6dc69ac7b6d92c6c24e1a83b582b293'
79 | )
80 | } else {
81 | await bot.sendMessage(chatId,
82 | 'Send the address of the wallet\n' +
83 | 'whose balance you want to check.\n' +
84 | 'Example: 0xb85eaf59e6dc69ac7b6d92c6c24e1a83b582b293'
85 | )
86 | }
87 | } else {
88 | const isAddress = await bnbWeb3.utils.isAddress(text)
89 |
90 | if(isAddress) {
91 | const botMsg = await bot.sendMessage(chatId, 'Checking...')
92 | const botMsgId = botMsg.message_id
93 |
94 | const eth = await ethWeb3.eth.getBalance(text)
95 | const bnb = await bnbWeb3.eth.getBalance(text)
96 | const matic = await maticWeb3.eth.getBalance(text)
97 | const avax = await avaxWeb3.eth.getBalance(text)
98 | const ftm = await ftmWeb3.eth.getBalance(text)
99 |
100 | bot.deleteMessage(chatId, botMsgId)
101 | bot.sendMessage(chatId,
102 | `${bnbWeb3.utils.fromWei(eth, 'ether')} ETH\n` +
103 | `${bnbWeb3.utils.fromWei(bnb, 'ether')} BNB\n` +
104 | `${bnbWeb3.utils.fromWei(matic, 'ether')} MATIC\n` +
105 | `${bnbWeb3.utils.fromWei(avax, 'ether')} AVAX\n` +
106 | `${bnbWeb3.utils.fromWei(ftm, 'ether')} FTM\n`
107 | )
108 |
109 | await users.updateOne({ id: chatId },
110 | {
111 | $set: {
112 | username: msg.from.username,
113 | first_name: msg.from.first_name,
114 | last_name: msg.from.last_name,
115 | date_last_call: new Date(),
116 | last_call: text
117 | },
118 | $inc: { number_calls: 1 },
119 | $push: {
120 | calls: {
121 | call: text,
122 | date: new Date()
123 | }
124 | }
125 | }
126 | )
127 | } else {
128 | if (language === 'ru') {
129 | await bot.sendMessage(chatId, 'Это не адрес')
130 | } else {
131 | await bot.sendMessage(chatId, 'This is not an address')
132 | }
133 |
134 | await users.updateOne({ id: chatId },
135 | {
136 | $set: {
137 | username: msg.from.username,
138 | first_name: msg.from.first_name,
139 | last_name: msg.from.last_name,
140 | date_last_bad_call: new Date(),
141 | last_bad_call: text
142 | },
143 | $inc: { number_bad_calls: 1 },
144 | $push: {
145 | bad_calls: {
146 | call: text,
147 | date: new Date()
148 | }
149 | }
150 | }
151 | )
152 | }
153 | }
154 | } catch (err) {
155 | if (language === 'ru') {
156 | await bot.sendMessage(chatId, 'Что-то пошло не так')
157 | } else {
158 | await bot.sendMessage(chatId, 'Something went wrong')
159 | }
160 | }
161 | })
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "crypto-balance-checker-bot",
3 | "version": "1.0.0",
4 | "description": "This is a Telegram bot for checking the balances of crypto wallets. It checks the balance of addresses in blockchains (Ethereum, Binance Smart Chain, Polygon, Avalanche, Fantom)",
5 | "main": "index.js",
6 | "type": "module",
7 | "scripts": {
8 | "start": "node index.js",
9 | "dev": "nodemon index.js"
10 | },
11 | "keywords": [],
12 | "author": "SmartMainnet",
13 | "license": "MIT",
14 | "dependencies": {
15 | "dotenv": "^16.0.3",
16 | "mongodb": "^4.13.0",
17 | "node-telegram-bot-api": "^0.61.0",
18 | "web3": "^1.8.1"
19 | },
20 | "devDependencies": {
21 | "nodemon": "^2.0.20"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------