【发布时间】:2018-09-26 00:12:57
【问题描述】:
pragma solidity ^0.4.17
contract Test {
event greeting(string name);
function say() pure public {
greeting('jack');
}
}
在 python 版本 web3.py 中调用 say() 函数时如何获取事件数据“jack”?下面是我的python代码。
contractAddress = '0x345ca3e014aaf5dca488057592ee47305d9b3e10'
contract = w3.eth.contract(address=contractAddress, abi=abiJson['abi'])
accounts = w3.eth.accounts
def handle_event(event):
print(event)
def log_loop(event_filter, poll_interval):
while True:
for event in event_filter.get_new_entries():
handle_event(event)
time.sleep(poll_interval)
block_filter = w3.eth.filter({'fromBlock':'latest', 'address':contractAddress})
log_loop(block_filter, 2)
【问题讨论】:
-
更多背景知识会有所帮助:运行代码时会发生什么?你用的是什么版本的 web3py?你用的是什么节点?你是如何触发事件的?
-
问题已经解决了: