Skip to content

Instantly share code, notes, and snippets.

@nheingit
Last active August 18, 2022 20:22
Show Gist options
  • Save nheingit/992588bf32114e2c0e36783f3f506678 to your computer and use it in GitHub Desktop.
Save nheingit/992588bf32114e2c0e36783f3f506678 to your computer and use it in GitHub Desktop.
paginate transactions
import requests
def flatten_list(_2d_list):
flat_list = []
# Iterate through the outer list
for element in _2d_list:
if type(element) is list:
# If the element is of type list, iterate through the sublist
for item in element:
flat_list.append(item)
else:
flat_list.append(element)
return flat_list
transaction_list_length = 1000
all_transactions = []
pubkey = "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"
transaction_list = requests.post(
"QUICKNODE_URL",
json={
"jsonrpc": "2.0",
"id": 1,
"method": "getSignaturesForAddress",
"params": [pubkey,{"limit": transaction_list_length}]
},
headers={'accept-encoding': 'gzip'}
)
all_transactions.append(transaction_list.json()['result'])
while transaction_list_length >= 1000:
last_signature = all_transactions[-1][-1]
transaction_list = requests.post(
"QUICKNODE_URL",
json={
"jsonrpc": "2.0",
"id": 1,
"method": "getSignaturesForAddress",
"params": [pubkey,{"before": last_signature['signature']}]
},
headers={'accept-encoding': 'gzip'}
).json()['result']
all_transactions.append(transaction_list)
transaction_list_length = len(transaction_list)
print("current:", transaction_list_length)
print("total:", len(all_transactions))
all_transactions = flatten_list(all_transactions)
for obj in all_transactions:
print(obj['signature'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment