import json,requests
NR="https://bsc-mainnet.nodereal.io/v1/64a9df0874fb4a93b9d0a3849de012d3"
def nr(params):
    return requests.post(NR,json={"jsonrpc":"2.0","id":1,"method":"nr_getAssetTransfers","params":[params]},timeout=60).json()
out={}
for a in json.load(open('recips.json')):
    allt=[]
    for cat in ["external","internal"]:
        j=nr({"category":[cat],"toAddress":a,"order":"asc","maxCount":"0x14","excludeZeroValue":True})
        if 'error' in j: print(a,cat,j['error']); continue
        allt+=j['result']['transfers']
    allt.sort(key=lambda t:(int(t['blockNum'],16),t['id'] if t['category']=='external' else 0))
    out[a]=allt
    f=allt[0] if allt else None
    print(a, len(allt), f and (f['category'],int(f['blockNum'],16),f['from'],int(f['value'],16)/1e18,f['hash']))
json.dump(out,open('bnb_in.json','w'),indent=1)
