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

Function collect_events

examples/top_usdt.py:11–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9load_dotenv()
10
11async def collect_events():
12 bearer_token = os.getenv("ENVIO_API_TOKEN")
13 if not bearer_token:
14 raise ValueError("ENVIO_API_TOKEN environment variable is required. Please set it in your .env file.")
15
16 client = hypersync.HypersyncClient(ClientConfig(
17 url="https://eth.hypersync.xyz/",
18 bearer_token=bearer_token
19 ))
20
21 height = await client.get_height()
22
23 query = hypersync.Query(
24 # start from 10k blocks back
25 from_block=height-int(1e4),
26 # Select the logs we want
27 logs=[LogSelection(
28 address=["0xdAC17F958D2ee523a2206206994597C13D831ec7"],
29 topics=[["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]],
30 )],
31 # Select the fields and tables we want
32 field_selection=FieldSelection(
33 log=[
34 LogField.TOPIC0,
35 LogField.TOPIC1,
36 LogField.TOPIC2,
37 LogField.DATA,
38 LogField.TRANSACTION_HASH,
39 ],
40 transaction=[
41 TransactionField.HASH,
42 TransactionField.GAS_USED,
43 ]
44 ),
45 )
46
47 config = hypersync.StreamConfig(
48 hex_output=hypersync.HexOutput.PREFIXED,
49 column_mapping=ColumnMapping(
50 # map value columns to float so we can do calculations with them
51 decoded_log={
52 "value": DataType.FLOAT64,
53 },
54 transaction={
55 TransactionField.GAS_USED: DataType.FLOAT64,
56 },
57 ),
58 # give event signature so client can decode logs into decoded_logs.parquet file
59 event_signature="Transfer(address indexed from, address indexed to, uint256 value)",
60 )
61
62 await client.collect_parquet("data", query, config)
63
64def analyze_events():
65 # read raw logs

Callers 1

top_usdt.pyFile · 0.85

Calls 6

get_heightMethod · 0.95
collect_parquetMethod · 0.95
ClientConfigClass · 0.90
LogSelectionClass · 0.90
FieldSelectionClass · 0.90
ColumnMappingClass · 0.90

Tested by

no test coverage detected