MCPcopy Create free account
hub / github.com/enviodev/hypersync-client-python / main

Function main

examples/tx_by_hash.py:15–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13load_dotenv()
14
15async def main():
16 bearer_token = os.getenv("ENVIO_API_TOKEN")
17 if not bearer_token:
18 raise ValueError("ENVIO_API_TOKEN environment variable is required. Please set it in your .env file.")
19
20 client = hypersync.HypersyncClient(ClientConfig(
21 url="https://eth.hypersync.xyz/",
22 bearer_token=bearer_token
23 ))
24
25 # The query to run
26 query = hypersync.Query(
27 from_block=0,
28 join_mode=JoinMode.JOIN_NOTHING,
29 field_selection=hypersync.FieldSelection(
30 transaction=[
31 TransactionField.BLOCK_NUMBER,
32 TransactionField.TRANSACTION_INDEX,
33 TransactionField.HASH,
34 TransactionField.FROM,
35 TransactionField.TO,
36 TransactionField.VALUE,
37 TransactionField.INPUT,
38 ]
39 ),
40 transactions=[
41 TransactionSelection(
42 hash=[
43 "0x410eec15e380c6f23c2294ad714487b2300dd88a7eaa051835e0da07f16fc282"
44 ]
45 )
46 ],
47 )
48
49 print("Running the query...")
50
51 # Run the query once, the query is automatically paginated so it will return when it reaches some limit (time, response size etc.)
52 # 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
53 # res.next_block is equal to res.archive_height or query.to_block in case we specified an end block.
54 res = await client.get(query)
55
56 print(f"Ran the query once. Next block to query is {res.next_block}")
57
58 print(res.data.transactions[0].from_)
59 print(res.data.transactions[0].to)
60
61
62asyncio.run(main())

Callers 1

tx_by_hash.pyFile · 0.70

Calls 3

getMethod · 0.95
ClientConfigClass · 0.90

Tested by

no test coverage detected