-
Notifications
You must be signed in to change notification settings - Fork 15
/
receipts.ts
109 lines (101 loc) · 2.52 KB
/
receipts.ts
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { JsonRpcProvider, Provider, TransactionReceipt } from 'ethers';
import { Inspector } from '../src/index.js';
import getProvider from './utils.js';
interface AlchemyTransactionReceipt {
blockHash: string;
blockNumber: string;
contractAddress: string;
cumulativeGasUsed: string;
effectiveGasPrice: string;
from: string;
gasUsed: string;
logs: {
address: string;
blockHash: string;
blockNumber: string;
data: string;
logIndex: string;
topics: string[];
transactionHash: string;
transactionIndex: string;
}[];
logsBloom: string;
status: string;
to: string | null;
transactionHash: string;
transactionIndex: string;
type: string;
}
const CHAIN_ID = 1;
async function run(): Promise<void> {
const provider = getProvider(CHAIN_ID);
const inspector = new Inspector(CHAIN_ID, provider);
const receipts = await getBlockReceipts(provider, 14769194);
const mev = await inspector.receipts(receipts);
console.log(mev);
}
async function getBlockReceipts(
provider: Provider,
number: number,
): Promise<TransactionReceipt[]> {
const response = await (provider as JsonRpcProvider).send(
'alchemy_getTransactionReceipts',
[{ blockNumber: `0x${number.toString(16)}` }],
);
return response.receipts.map((receipt: AlchemyTransactionReceipt) => {
const {
blockHash,
blockNumber,
contractAddress,
cumulativeGasUsed,
effectiveGasPrice,
from,
gasUsed,
logs,
logsBloom,
status,
to,
transactionHash,
transactionIndex,
type,
} = receipt;
return {
blockHash,
blockNumber: parseInt(blockNumber, 16),
contractAddress,
cumulativeGasUsed: BigInt(cumulativeGasUsed),
effectiveGasPrice: BigInt(effectiveGasPrice),
from,
gasUsed: BigInt(gasUsed),
logs: logs.map((log) => {
const {
address,
blockHash,
blockNumber,
data,
logIndex,
topics,
transactionHash,
transactionIndex,
} = log;
return {
address,
blockHash,
blockNumber: parseInt(blockNumber, 16),
data,
index: parseInt(logIndex, 16),
topics,
transactionHash,
transactionIndex: parseInt(transactionIndex, 16),
};
}),
logsBloom,
status: parseInt(status, 16),
to,
transactionHash,
transactionIndex: parseInt(transactionIndex, 16),
type: parseInt(type, 16),
};
});
}
run();