1

I am new to blockchain and trying the get the transaction details from BscScan using python-API. I am using example as shown in the link.

from bscscan import BscScan
async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_bep20_token_transfer_events_by_address(
            address="0x63aea877b5d5fa234a1532f1b26a4f6d9051866e",
            startblock=0,
            endblock=999999999,
            sort="asc"
        )
    )

This example shows some details but not all. For example, it does not show "Tokens Transferred" details such as: Image.

I have few questions, hope someone will help me finding the answer.

  1. How can I get amount paid, and in what currency from the transaction as shown in the image?
  2. How much tokens are received?
  3. Above example returns "timeStamp": "1611843685". How can I convert it to actual date like: 2021-06-07?

If there is another better API (not necessarily python ) to get details, please let me know.

Thanks in advance.

BasicTex
  • 89
  • 1
  • 10
  • https://stackoverflow.com/questions/3682748/converting-unix-timestamp-string-to-readable-date – Shlomi Bazel Jun 26 '21 at 14:51
  • Hi BasicTex, just wondering if you manage to get the token transferred details later from the API. I saw that you intended to get the data from web site directly by crawling. Have you got it done successfully? – Tim Hong Dec 29 '21 at 07:22

1 Answers1

0

This is what I did to get transactions info. I'm not sure if we're referring to the same thing,but for me, I wanted to get the DEX trades of a particular specified token. Here is my code. Btw you have to put in your own API key and token address. Also, I took away many variables that I deemed useless.

import requests
from datetime import datetime
import pandas as pd

API_KEY = ''

#Get a list of "BEP-20 - Token Transfer Events" by Address

ADDRESS = ''

url = 'https://api.bscscan.com/api?module=account&action=tokentx&contractaddress='+ADDRESS+'&page=1&offset=100&sort=desc&apikey=' + API_KEY

response = requests.get(url)

transactions = []
for i in response.json()['result']:
    #print(i)
    ts = int(i['timeStamp'])
    temp = {
        'timeStamp': datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S'),
        'from': i['from'],
        'to': i['to'],
        'value': int(i['value'])/1000000000000000000,
        'tokenName': i['tokenName']
    }
    #print(temp)
    transactions.append(temp)

pd.DataFrame(transactions)
hengjuice
  • 112
  • 1
  • 1
  • 9
  • Thanks for your post. But I am looking for tracing my own transactions for various BEP-20 tokens. Your code only does it for a specific token. It also takes only first 100 transactions. – BasicTex Aug 19 '21 at 16:12
  • I am more interested to find the amount spent to purchase coins. In above code value will only return the number of tokens received and does not tell you the amount you spent. – BasicTex Aug 25 '21 at 05:43