Exemple #1
0
def gettokenamount(walletaddress, contractaddress):
    logger.info(("Initializing object to easilty get the token amount for "
                 "address: {} and contract {}").format(walletaddress,
                                                       contractaddress))
    esurl = ("https://api.etherscan.io/api"
             "?module=account"
             "&action=tokenbalance"
             "&contractaddress={}"
             "&address={}"
             "&apikey={}").format(contractaddress, walletaddress,
                                  settings.config.etherscanapikey)

    logger.info("The Etherscan get balance URL is: {}".format(esurl))
    try:
        json = get_json_from_url(esurl)
        logger.info("The JSON file is succesfully retrieved")
        amount = Decimal(json["result"]) / 1000000000000000000
        logger.info("The amount of tokens found is {}".format(amount))

    except:
        logger.error("Can't retrieve the JSON file from the url")
        raise Exception(
            "Can't retrieve the JSON file from the get balance url")

    return amount
Exemple #2
0
 def get_content(self):
     cgurl = ("https://api.coingecko.com/api/v3/coins/ethereum/contract/"
     "{}").format(self.contractaddress)
     logger.info("The Coingecko transaction URL is: {}".format(
         cgurl))
     try:
         self.json = get_json_from_url(cgurl)
         logger.info("The JSON file is succesfully retrieved")
     except:
         logger.error("Can't retrieve the JSON file from the url")
 def __init__(self, timeout=300):
     self.json = None
     self.timeout = timeout
     method = "getUpdates"
     # Offset = last update id + 1 (imported from settings file)
     offset = str(int(settings.config.telegramlastprocessedupdateid) + 1)
     parameters = {"timeout": timeout, "offset": offset}
     self.apiurl = super().apiurl(method=method, parameters=parameters)
     logger.info("Get new updates for the bot via the Telegram API")
     self.json = get_json_from_url(self.apiurl)
 def get_content(self):
     esurl = ("https://api.etherscan.io/api"
         "?module=proxy"
         "&action=eth_getTransactionReceipt"
         "&txhash={}"
         "&apikey={}").format(self.txhash,settings.config.etherscanapikey)
     logger.info("The Etherscan Uniswap transaction URL is: {}".format(
         esurl))
     try:
         self.json = get_json_from_url(esurl)
         logger.info("The JSON file is succesfully retrieved")
     except:
         logger.error("Can't retrieve the JSON file from the url")
Exemple #5
0
def lastblock():
    esurl = (
        "https://api.etherscan.io/api?module=proxy&action=eth_blockNumber&"
        "apikey={}".format(settings.config.etherscanapikey))
    logger.info("Get last blocknumber from EtherScan url {}".format(esurl))
    try:
        json = get_json_from_url(esurl)
        blocknumber = int(json["result"], 16)
    except:
        logger.error("Can't retrieve blocknumber from URL")
        raise Exception(
            "Can't retrieve blocknumber from url. Error: {}".format(
                sys.exc_info()[0]))

    return blocknumber
Exemple #6
0
    def __init__(self,
                 chat_id,
                 text,
                 formatstyle="HTML",
                 disablewebpreview="True"):
        self.json = None
        method = "sendMessage"
        formattedtext = urllib.parse.quote_plus(text)
        parameters = {
            "chat_id": chat_id,
            "text": formattedtext,
            "parse_mode": formatstyle,
            "disable_web_page_preview": disablewebpreview
        }
        self.apiurl = super().apiurl(method=method, parameters=parameters)

        logger.info("Sending message: {} to: {}".format(text, chat_id))
        self.json = get_json_from_url(self.apiurl)
    def get_uniswaptransactions(self):
        esurl = ("https://api.etherscan.io/api"
                 "?module=account"
                 "&action=tokentx"
                 "&startblock={}"
                 "&address={}"
                 "&contractaddress={}"
                 "&apikey={}".format(
                     self.startblock, settings.config.uniswapaddress,
                     settings.config.primarytokencontractaddress,
                     settings.config.etherscanapikey))

        logger.info(
            "The Etherscan Uniswap transaction batch URL is: {}".format(esurl))
        try:
            self.json = get_json_from_url(esurl)
            logger.info("The JSON file is succesfully retrieved")
        except:
            logger.error("Can't retrieve the JSON file from the url")