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

Function main

examples/all_erc20_transfers.py:12–91  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10# For a more complex example with multiple events, see all-erc20-transfer-and-approve.py
11
12async def main():
13 bearer_token = os.getenv("ENVIO_API_TOKEN")
14 if not bearer_token:
15 raise ValueError("ENVIO_API_TOKEN environment variable is required. Please set it in your .env file.")
16
17 client = hypersync.HypersyncClient(ClientConfig(
18 url="https://eth.hypersync.xyz/",
19 bearer_token=bearer_token
20 ))
21
22 # The query to run
23 query = hypersync.Query(
24 # start from block 0 and go to the end of the chain (we don't specify a toBlock).
25 from_block=0,
26 # The logs we want. We will also automatically get transactions and blocks relating to these logs (the query implicitly joins them).
27 logs=[
28 hypersync.LogSelection(
29 # We want All ERC20 transfers so no address filter and only a filter for the first topic
30 topics=[
31 [
32 "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
33 ]
34 ]
35 )
36 ],
37 # Select the fields we are interested in, notice topics are selected as topic0,1,2,3
38 field_selection=hypersync.FieldSelection(
39 block=[BlockField.NUMBER, BlockField.TIMESTAMP, BlockField.HASH],
40 log=[
41 LogField.LOG_INDEX,
42 LogField.TRANSACTION_INDEX,
43 LogField.TRANSACTION_HASH,
44 LogField.DATA,
45 LogField.ADDRESS,
46 LogField.TOPIC0,
47 LogField.TOPIC1,
48 LogField.TOPIC2,
49 LogField.TOPIC3,
50 ],
51 transaction=[
52 TransactionField.BLOCK_NUMBER,
53 TransactionField.TRANSACTION_INDEX,
54 TransactionField.HASH,
55 TransactionField.FROM,
56 TransactionField.TO,
57 TransactionField.VALUE,
58 TransactionField.INPUT,
59 ],
60 ),
61 )
62
63 # start the stream
64 receiver = await client.stream(query, hypersync.StreamConfig())
65
66 decoder = hypersync.Decoder(
67 ["Transfer(address indexed from, address indexed to, uint256 value)"]
68 )
69

Callers 1

Calls 4

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

Tested by

no test coverage detected