[Python] How to get all transactions?

Hello, I’m trying to build BSC Wallet tracker in Python and I want to get all transactions from Moralis API and here is my problem:

When I’m trying to get all transactions I only get first 500 tx’s and i dont know how to get all transactions i tried to play with “offset” and “limit” functions but i dont understand how… I mean i dont know what to put in offest or limit to get all transactions. here is my code:

import requests
import json

fee_used_as_sender = []
fee_used_as_sender.clear()

fee_used_as_reciver = []
fee_used_as_reciver.clear()

def fee_counter():
    headers= {'x-api-key':'API KEY'}

    wallet_address = 'BSC WALLET ADDRES HERE'
    txs_url = 'https://deep-index.moralis.io/api/v2/' + wallet_address + '?chain=bsc'
    response = requests.get(txs_url,headers=headers).text
    txs = json.loads(response)

    n = 0

    while n < 500:
        native_tx_result = txs['result'][n]
        from_address = native_tx_result['from_address']
        receipt_gas_used = native_tx_result['receipt_gas_used']
        gas_price = native_tx_result['gas_price']
        tx_hash = native_tx_result['hash']
        gas_price = '{0:,.8f}'.format(float(float(gas_price) / 10 ** 18))
        tx_fee =  float(gas_price) * float(receipt_gas_used)

        if from_address == wallet_address:
            fee_used_as_sender.append(tx_fee)
            n += 1
        else:
            fee_used_as_reciver.append(tx_fee)
            n += 1

    print("fee_used_as_sender: ", sum(fee_used_as_sender))
    print("fee_spent_as_reciver: ", sum(fee_used_as_reciver))

fee_counter()

Thanks in Advance

I know I have while n < 500: in the code but i have more then 500 txs on my wallet address

Hi,
Can you also provide your wallet address that you are testing with?

here 0x8d77af6392e6ED8e2fc01B36368B6020D4b4eB32 I found it on bscscan

Curl example:

curl -X 'GET' \
  'https://deep-index.moralis.io/api/v2/0x8d77af6392e6ED8e2fc01B36368B6020D4b4eB32?chain=bsc&offset=200&limit=20' \
  -H 'accept: application/json' \
  -H 'X-API-Key:API_KEY_HERE'

for offset mainly adding ?chain=bsc&offset=200&limit=20 as an example of how to use offset

1 Like

Thanks buddy <3 but there is different numbers of transactions on different wallets and how can i fix that?

you have the number of transactions per wallet in the initial request and in that way we can do a for loop to get all the transactions.

Or you can contact Kresimir#3615 for increasing output limit from Web3 API (now it is 500 objects)

The response that you get for the initial request starts like this:

{
  "total": 856,
  "page": 0,
  "page_size": 500,
  "result": [

and this way you can know what is the total number of transactions, and what is the default page size (500)

@Ghonghito, were you able to solve this or you still need additional help?