|
| 1 | +import asyncio |
| 2 | +import time |
| 3 | + |
| 4 | +from pyinjective.async_client import AsyncClient |
| 5 | +from pyinjective.client.model.pagination import PaginationOption |
| 6 | +from pyinjective.core.network import Network |
| 7 | + |
| 8 | + |
| 9 | +async def main() -> None: |
| 10 | + # Select network: local, testnet, mainnet, or custom |
| 11 | + network = Network.testnet() |
| 12 | + |
| 13 | + # Initialize client |
| 14 | + client = AsyncClient(network) |
| 15 | + |
| 16 | + try: |
| 17 | + # Example parameters for fetching contract transactions |
| 18 | + address = "inj1ady3s7whq30l4fx8sj3x6muv5mx4dfdlcpv8n7" # Replace with actual contract address |
| 19 | + |
| 20 | + # Optional pagination and filtering parameters |
| 21 | + pagination = PaginationOption( |
| 22 | + limit=10, |
| 23 | + start_time=int((time.time() - 100) * 1000), |
| 24 | + end_time=int(time.time() * 1000), |
| 25 | + ) |
| 26 | + |
| 27 | + # Fetch contract transactions V2 |
| 28 | + response = await client.fetch_contract_txs_v2(address=address, height=60_000_000, pagination=pagination) |
| 29 | + |
| 30 | + # Print the results |
| 31 | + print("Contract Transactions V2:") |
| 32 | + print("Total Transactions:", len(response["data"])) |
| 33 | + |
| 34 | + for tx in response["data"]: |
| 35 | + print("\nTransaction Details:") |
| 36 | + print("ID:", tx["id"]) |
| 37 | + print("Block Number:", tx["blockNumber"]) |
| 38 | + print("Timestamp:", tx["blockTimestamp"]) |
| 39 | + print("Hash:", tx["hash"]) |
| 40 | + print("Tx Number:", tx["txNumber"]) |
| 41 | + |
| 42 | + except Exception as e: |
| 43 | + print(f"Error occurred: {e}") |
| 44 | + |
| 45 | + |
| 46 | +if __name__ == "__main__": |
| 47 | + asyncio.get_event_loop().run_until_complete(main()) |
0 commit comments