Skip to content

Instantly share code, notes, and snippets.

@Reecepbcups
Created January 2, 2024 18:40
Show Gist options
  • Save Reecepbcups/fa0d810eb4bc54d7c741ad6bdde9d215 to your computer and use it in GitHub Desktop.
Save Reecepbcups/fa0d810eb4bc54d7c741ad6bdde9d215 to your computer and use it in GitHub Desktop.
Gets all transactions for an address via Mintscan's beta API
# https://api.mintscan.io/dashboard
import json
from typing import List
from httpx import get
addr = "juno1lykvggsfnywqhsmqz346p567aejrn4gp06p5w4"
headers = {
"Authorization": "Bearer PRIV-TOKEN-HERE",
"Accept": "application/json",
}
class Tx:
def __init__(self, height, txhash, data, gas_wanted, gas_used, tx, timestamp):
self.height = height
self.txhash = txhash
self.data = data
self.gas_wanted = gas_wanted
self.gas_used = gas_used
self.tx = tx
self.timestamp = timestamp
def __str__(self):
return f"Tx(height={self.height}, txhash={self.txhash}, data={self.data}, gas_wanted={self.gas_wanted}, gas_used={self.gas_used}, tx={self.tx}, timestamp={self.timestamp})"
def __repr__(self):
return self.__str__()
all_txs: List[Tx] = []
def make_query(search_after: str):
print(search_after)
global all_txs
req_url = f"https://apis.mintscan.io/v1/juno/accounts/{addr}/transactions?take=20"
if len(search_after) != 0:
req_url += f"&searchAfter={search_after}"
response = get(req_url, headers=headers)
res = response.json()
for tx in res["transactions"]:
all_txs.append(
Tx(
height=tx["height"],
txhash=tx["txhash"],
data=tx["data"],
gas_wanted=tx["gas_wanted"],
gas_used=tx["gas_used"],
tx=tx["tx"],
timestamp=tx["timestamp"],
)
)
with open("all_txs.json", "w") as f:
json.dump([tx.__dict__ for tx in all_txs], f)
pag = res["pagination"]
if pag.get("searchAfter") is None:
return
else:
make_query(pag["searchAfter"])
if __name__ == "__main__":
make_query("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment