-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
41 lines (32 loc) · 1.14 KB
/
index.py
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
from dotenv import load_dotenv
import os, time
from bundle import Bundle, getRawTransactionHash
from web3 import Web3
from blocknative.stream import Stream
w3 = Web3(Web3.HTTPProvider(os.environ.get("RPC_PROVIDER")))
##### build your own raw transaction hash ####
# data = "<SOME DATA>"
# bundle = Bundle()
# gas = 500000
# gasPrice = 50000000000 #50 GWEI
# tx = bundle.getMyRawTransaction(data, gas, gasPrice)
# blockNumber = w3.eth.blockNumber
# response = bundle.makeRpcCall("callRpc", [tx], blockNumber)
# print(response)
# use blocknative sdk to get raw transaction hash from mempool payload
load_dotenv()
API_KEY = os.environ.get("API_KEY")
monitor_address = "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45" #uniswap autorouter
global_filters = [{
'status': 'pending'
}]
async def txn_handler(txn, unsubscribe):
# print(txn)
rawTxHash = getRawTransactionHash(txn)
time.sleep(1)
checkRawTxHash = w3.eth.get_raw_transaction(txn['hash']).hex()
print(rawTxHash==checkRawTxHash)
if __name__ == '__main__':
stream = Stream(API_KEY, global_filters=global_filters)
stream.subscribe_address(monitor_address, txn_handler)
stream.connect()