简体   繁体   English

如何获取事件日志 Web3.py?

[英]How to get event log Web3.py?

I am using solidity 0.7.4, web3.py 5.12.2, and python 3.7.我正在使用solidity 0.7.4、web3.py 5.12.2 和python 3.7。

I am working with Windows 10.我正在使用 Windows 10。

My goal is to emit an event inside a solidity function, in order to retrieve the log after the function is executed.我的目标是在solidity 函数内发出一个事件,以便在函数执行后检索日志。

This is my event event logString(string arg);这是我的事件event logString(string arg);

And this is how I emit the event emit logString("example string");这就是我发出事件的方式emit logString("example string");

On Remix it works, and I am able to retrieve the string I emit, in the log of the transaction.在 Remix 上它可以工作,并且我能够在事务日志中检索我发出的字符串。

When I try it on Python, it doesn't work.当我在 Python 上尝试时,它不起作用。

This is my Python code:这是我的 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']

Unfortunately tx_receipt['logs'] is empty and I get an exception.不幸的是tx_receipt['logs']是空的,我得到一个例外。

Do you know how can I retrieve the log of the event?您知道如何检索事件日志吗?

I managed to solve the problem.我设法解决了这个问题。 I don't know why, I had to exactly specify the network_id in the truffle config.js.我不知道为什么,我必须在 truffle config.js 中准确指定 network_id。 Then I migrated the contracts again and ran ganache-cli on that specific network_id.然后我再次迁移合约并在该特定 network_id 上运行 ganache-cli。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在web3.py中的代币池合约中直接获取BSC代币的价格 - How to get the price of BSC token directly the token pool contract in web3.py 如何在 Python 和 web3.py 中获取 Solidity 恢复/需要错误原因 - How to get Solidity revert/require error reason in Python and web3.py 如何使用合约交互从 web3.py 获取未签名的交易数据 - How to get an unsigned transaction data from web3.py using contract interaction 如何在 python/web3.py 中每 3 秒获取一次当前的 WBNB 余额? - How can I get the current WBNB balance once every 3 seconds in python/web3.py? 如何使用 web3.py 在给定的 ETH 地址获取特定的代币余额 - How to get the specific token balance available at a give ETH address using web3.py 如何在 PancakeSwap 上使用 Web3.py 获取令牌的确切值? Function getAmountsOut() 返回错误值 - How to get exact value of a token with Web3.py on PancakeSwap? Function getAmountsOut() returns a wrong value web3.py function get_block 交易不在当前区块中 - web3.py function get_block tranactions is not in the current block bsc 通过钱包地址获取交易 Web3.py - bsc get transactions by wallet address Web3.py 使用 web3.py 通过块哈希获取 Avalanche 块数据 - Get Avalanche block data by block hash with web3.py web3.py 从获取 function 以奇怪的格式返回 - web3.py return from a get function in strange format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM