I am using solidity 0.7.4, web3.py 5.12.2, and python 3.7.

I am working with Windows 10.

My goal is to emit an event inside a solidity function, in order to retrieve the log after the function is executed.

This is my event event logString(string arg);

And this is how I emit the event emit logString("example string");

On Remix it works, and I am able to retrieve the string I emit, in the log of the transaction.

When I try it on Python, it doesn't work.

This is my Python code:

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.

Do you know how can I retrieve the log of the event?

  • Did you wait the transaction to me be mined? Nov 19, 2020 at 19:17
  • Of course. I even stopped the execution with the debugger. I can clearly see the transaction hash on ganache-cli and I am able to retrieve the transaction receipt. Just the logs are empty. It works on the remix debugger though. Nov 19, 2020 at 19:40
  • It seems like when I deploy (migrate ) from Truffle, the logs of the transactions are empty. I don't know why Nov 20, 2020 at 8:46
  • Also see that you are using the web3.py API correctly - there is specifically a method of getting past events Nov 20, 2020 at 9:31
  • Can you please help me to find it? The documentation is poor. And actually my code works when the contract is deployed by remix. Nov 20, 2020 at 13:21

1 Answer 1


I managed to solve the problem. I don't know why, I had to exactly specify the network_id in the truffle config.js. Then I migrated the contracts again and ran ganache-cli on that specific network_id.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.