-
Notifications
You must be signed in to change notification settings - Fork 0
/
08.py
59 lines (38 loc) · 1.45 KB
/
08.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from web3 import Web3
RPC_URL = 'https://rpc.ankr.com/eth' # connected to anvil
# connect to blockchain
web3 = Web3(Web3.HTTPProvider(RPC_URL))
print(f'Connected: {web3.is_connected()}')
# get Chain id
print(f'Chain ID: {web3.eth.chain_id}')
block = web3.eth.get_block('latest') # every 15 seconds
print(block)
# get block number
def get_block_number():
# get latest block number
block_num = web3.eth.get_block_number()
print(block_num)
# get block hash
def get_block_hash():
print("hmm..")
def get_transactions_in_block():
block = web3.eth.get_block('latest')
for transactions in block['transactions']:
# get transaction hashT
value = web3.to_hex(transactions)
# get transaction details for hash
# print(web3.eth.getTransaction(transactions))
# get transaction count in block
# print(web3.eth.get_block_transaction_count(block.))
get_transactions_in_block()
def look_for_approve_func():
for transactions in block.transactions:
# get transaction hash
# print(web3.toHex(transactions))
# get transaction details for hash
value = web3.eth.get_transaction(transactions)
# this is the approve function signature
# if '095ea7b3' in web3.toHex(value['input']), this will return true
if '095ea7b3' in web3.to_hex(transactions):
print(
f'found an approve transaction: {web3.eth.get_transaction(value["hash"])}')