-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtx_by_hash.py
More file actions
62 lines (52 loc) · 1.9 KB
/
tx_by_hash.py
File metadata and controls
62 lines (52 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
from dotenv import load_dotenv
import hypersync
import asyncio
from hypersync import (
JoinMode,
TransactionField,
ClientConfig,
TransactionSelection,
)
# Load environment variables from a .env file
load_dotenv()
async def main():
bearer_token = os.getenv("ENVIO_API_TOKEN")
if not bearer_token:
raise ValueError("ENVIO_API_TOKEN environment variable is required. Please set it in your .env file.")
client = hypersync.HypersyncClient(ClientConfig(
url="https://eth.hypersync.xyz/",
bearer_token=bearer_token
))
# The query to run
query = hypersync.Query(
from_block=0,
join_mode=JoinMode.JOIN_NOTHING,
field_selection=hypersync.FieldSelection(
transaction=[
TransactionField.BLOCK_NUMBER,
TransactionField.TRANSACTION_INDEX,
TransactionField.HASH,
TransactionField.FROM,
TransactionField.TO,
TransactionField.VALUE,
TransactionField.INPUT,
]
),
transactions=[
TransactionSelection(
hash=[
"0x410eec15e380c6f23c2294ad714487b2300dd88a7eaa051835e0da07f16fc282"
]
)
],
)
print("Running the query...")
# Run the query once, the query is automatically paginated so it will return when it reaches some limit (time, response size etc.)
# there is a next_block field on the response object so we can set the from_block of our query to this value and continue our query until
# res.next_block is equal to res.archive_height or query.to_block in case we specified an end block.
res = await client.get(query)
print(f"Ran the query once. Next block to query is {res.next_block}")
print(res.data.transactions[0].from_)
print(res.data.transactions[0].to)
asyncio.run(main())