python - 如何获取事件日志 Web3.py?
问题描述
我正在使用solidity 0.7.4、web3.py 5.12.2 和python 3.7。
我正在使用 Windows 10。
我的目标是在solidity函数中发出一个事件,以便在函数执行后检索日志。
这是我的活动event logString(string arg);
这就是我发出事件的方式emit logString("example string");
在 Remix 上它可以工作,并且我能够在事务日志中检索我发出的字符串。
当我在 Python 上尝试它时,它不起作用。
这是我的 Python 代码:
web3_instance = Web3(HTTPProvider("http://"+host+":"+port, request_kwargs={'timeout': timeout}))
Platform_contract= web3_instance.eth.contract(address=contract_address, abi=abi, bytecode=bytecode)
coinbase= web3_instance.eth.coinbase
functions= Platform_contract.functions
tx_hash =functions.market_clearing(n_clearings, t_clearing_first,supplier_bids,uniform_pricing,discriminative_pricing).transact({'from': coinbase})
tx_receipt = web3_instance.eth.getTransactionReceipt(tx_hash)
log_to_process = tx_receipt['logs'][0]
processed_log = Platform_contract.events.logString().processLog(log_to_process)
log = processed_log['args']['arg']
不幸tx_receipt['logs']
的是是空的,我得到了一个例外。
您知道如何检索事件日志吗?
解决方案
我设法解决了这个问题。我不知道为什么,我必须在 truffle config.js 中准确指定 network_id。然后我再次迁移合同并在该特定 network_id 上运行 ganache-cli。
推荐阅读
- delphi - Delphi 组件自定义属性不保存在 DFM 文件中
- git - 存储库中的 Git 属性
- css - 如何水平溢出相对于垂直滚动条的位置(在ngx-virtual-scroller中创建弹出窗口)
- python - 通过 turbodc 将 dask 数据帧写入 mssql 时出错
- razor - 我的 RedirectToPage 在 Razor 页面中不起作用
- java - 在我的 XPage 中实现 OpenNTF DOmino API,我应该对代码进行哪些更改?
- c# - Powershell [double]::parse() 问题
- javascript - 打开图层功能在缩小时移动
- java - 使用 Maven 依赖项的轻量级方法?
- c - 使用后如何正确删除信号量?