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

Function main

examples/all_erc20_transfer_and_approve.py:15–120  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13approval_topic = "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925"
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 # start from block 0 and go to the end of the chain (we don't specify a toBlock).
28 from_block=0,
29 # The logs we want. We will also automatically get transactions and blocks relating to these logs (the query implicitly joins them).
30 logs=[
31 hypersync.LogSelection(
32 # We want All ERC20 transfers so no address filter and only a filter for the first topic
33 topics=[
34 [
35 transfer_topic
36 ],
37 ]
38 ),
39 # We need to place the approvals topic in a separate log selection so that it acts as an OR (logical).
40 hypersync.LogSelection(
41 # We want All ERC20 approvals so no address filter and only a filter for the first topic
42 topics=[
43 [
44 approval_topic
45 ],
46 ]
47 )
48 ],
49 # Select the fields we are interested in, notice topics are selected as topic0,1,2,3
50 field_selection=hypersync.FieldSelection(
51 block=[BlockField.NUMBER, BlockField.TIMESTAMP, BlockField.HASH],
52 log=[
53 LogField.LOG_INDEX,
54 LogField.TRANSACTION_INDEX,
55 LogField.TRANSACTION_HASH,
56 LogField.DATA,
57 LogField.ADDRESS,
58 LogField.TOPIC0,
59 LogField.TOPIC1,
60 LogField.TOPIC2,
61 LogField.TOPIC3,
62 ],
63 transaction=[
64 TransactionField.BLOCK_NUMBER,
65 TransactionField.TRANSACTION_INDEX,
66 TransactionField.HASH,
67 TransactionField.FROM,
68 TransactionField.TO,
69 TransactionField.VALUE,
70 TransactionField.INPUT,
71 ],
72 ),

Calls 4

streamMethod · 0.95
decode_logsMethod · 0.95
ClientConfigClass · 0.90
recvMethod · 0.45

Tested by

no test coverage detected