I am trying to get data from earlier blocks/transactions.

I have created events and emitted them.

I can see the logs in the Remix IDE.

However, I cannot get the logs in web3.py. It only returns empty.

Is there any function that can return all of the logs generated by an event?

Here is my Smart Contract

pragma solidity 0.8.0;

contract UserRep {
    mapping(uint256 => User) users;
    uint256[] userIDList;
    struct User {
        uint256 id;
        //other attributes
       // string[] data;
        bool isMalicious;
        uint256 rep_value;
    event reputationOfUser(uint256 userId, uint256 repVal );

    // Create a new user.
    function newUser(uint256 _id) public {
        // In a mapping, all elements are defined. They're just empty by default
        // So, just setting the id will create a new user;
        users[_id].id = _id;
        users[_id].rep_value = 50;
    // Add reputation value of a user
    function increaseReputation(uint256 _id, uint256 _addRep) public {
        users[_id].rep_value = users[_id].rep_value + _addRep; 
        emit reputationOfUser(users[_id].id, users[_id].rep_value);
    // Decrease the reputation value of a vehicle
    function decreaseReputation (uint256 _id, uint256 _decRep) public{
        if (users[_id].rep_value < 10){
            users[_id].isMalicious = true;
        users[_id].rep_value = users[_id].rep_value - _decRep;
       // emit reputationOfUser(users[_id], users[_id].rep_value);
    function getUserReputation(uint256 _id) public view returns (uint256){
        return users[_id].rep_value;
    function isUserMal(uint256 _id) public view returns (bool){
        if (users[_id].rep_value < 10){
            return true;
            return false;
    function getAllUserIDs() public view returns  (uint256[] memory){
        return userIDList;
    function noOfUsers() public view returns  (uint256){
        return userIDList.length;

  • Hi! It would be helpful if you also provide the web3.py code you've been trying, and what errors you've gotten. Cheers! – The Renaissance Apr 5 at 11:50
  • Hi sir, I have tried [[ logs = deployed_contract.events.userGen().processReceipt(receipt) ]] ... It gives this error. [[ UserWarning: The log with transaction hash: b'\xed9^\xa00T\xa7\xa91\x02\x8f>\x12\x7f\xc2 \xd8\xd2>&\xbf\x8b\x8c\xfa\xf7\xdb\x05\xc1S:\xba\xa4' and logIndex: 0 encountered the following error during processing: LogTopicError(Expected 0 log topics. Got 1). It has been discarded. warnings.warn( ]]. The logs variable is an empty list. – resilientEther Apr 5 at 13:22
  • If you know the proper way to return logs from a specific transaction / Block, then please share it with me.. My aim is to get a past value of a variable. – resilientEther Apr 5 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.