Skip to content

Instantly share code, notes, and snippets.

@aligalehban
Created November 7, 2021 20:46
Show Gist options
  • Save aligalehban/4716a38fb4991466c91575c4edde6bd5 to your computer and use it in GitHub Desktop.
Save aligalehban/4716a38fb4991466c91575c4edde6bd5 to your computer and use it in GitHub Desktop.
Telegram bot to check ETH , XRP, Doge wallet Balance
#developer Ali Ghalehban
import telebot
from telebot.types import Message
import json
import requests
import re
usdprice=1
# assiging constant values
token = ""
bot = telebot.TeleBot("")
# intial messages
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.reply_to(message, "Welcome to Chkbalancebot enter Your wallet ")
# getting wallet deatil and responcing balance
@bot.message_handler(func=lambda message: True)
def echo_all(message):
wallet = message.text
if re.match(r'^D', wallet):
dogecoin(wallet, message)
elif re.match(r'^r', wallet):
XRP(wallet, message)
elif re.match(r'^0x', wallet):
ethcheck(wallet, message)
else:
bot.reply_to(message, "wrong wallet format")
# ETH balance check
def ethcheck(wallet, message):
request = requests.get(
"https://api.etherscan.io/api?module=account&action=balance&address="+wallet+"&tag=latest&apikey="+token).text
a = json.loads(request)
balance = float(a['result'])
finalbalance = balance / 1000000000000000000
finalbalance = round(finalbalance, 3)
bot.reply_to(message, "ٌyour Balance is : " + str(finalbalance) + " ETH & USD: "+str((float(finalbalance)*int(price()))) )
# function will get ETH USD price
def price():
request = requests.get("https://api.nanopool.org/v1/eth/prices").text
a = json.loads(request)
dict_test['price_usd'] = a['data']['price_usd']
return (int(dict_test["price_usd"]))
# DOGE balance check
def dogecoin(wallet, message):
request = requests.get(
"https://dogechain.info/api/v1/address/balance/"+wallet).text
a = json.loads(request)
balance = float(a['balance'])
balance = round(balance, 3)
bot.reply_to(message, "ٌyour Balance is : " + str(balance) + " DOGE")
# XRP balance check
def XRP(wallet, message):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0'
}
request = requests.get("http://api.xrpscan.com/api/v1/account/"+str(wallet),headers=headers,)
a = json.loads(request.text)
balance = float(a["xrpBalance"])
balance = round(balance, 3)
bot.reply_to(message, "ٌyour Balance is : " + str(balance) + " XRP")
bot.polling()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment