web3.eth.filter 这个主要是用来监听得,如下代码块所示,就是监听每个新块得信息
from web3 import Web3
import time
import jsonbsc = "https://bsc-dataseed.binance.org/"
web3 = Web3(Web3.HTTPProvider(bsc))def handle_event(event):jsonEventContents = json.loads(Web3.toJSON(event))print(jsonEventContents)def log_loop(event_filter, poll_interval):while True:for event in event_filter.get_new_entries():handle_event(event)time.sleep(poll_interval)def main():block_filter = web3.eth.filter("latest")log_loop(block_filter, 2)if __name__ == '__main__':main()
如果用 “latest" ,"pengding"来监听,返回得hx值,如果按条件过滤,就会返回整个日志对象