0

I'm trying to figure out how to track the activity of users of my dapp and have a "history" page for them.

For this purpose I decided to set events and track them using web3.eth.filter

This works you can see in this image there is 1 topic showing corresponding to my event. It's a hash but it's my even.

https://i.imgur.com/Rw4fYSM.png

It's not showing the from address though. How am i supposed to know which user activated the event without it?

I thought it was possible to know the from address using eth.filter because when I use it from random addresses from etherscan, I'm seeing multiple topics and one of them is the from address.

https://i.imgur.com/uw6Qhyy.png

This is a screenshot of this random transaction https://etherscan.io/tx/0x20d783d6813e27c3083609228acbcb88b3a508533c101a6393489a82a40564e4

You can see the from address is in one of the topics. How can I get that?

The first screenshot I'm using remix and testrpc.

The second screenshot I'm using metamask's injected web3 inside chrome console and mainnet with a random etherscan address.

// This is my contract

contract Test {

    event event1(uint id);
    event event2(string name);
    uint id = 1;

    function buy() public payable {

        event1(id);
        event2('testing');
        id++;

    }

}

// This is what I get when I do web3.eth.filter in remix on testrpc
// The topics are not showing the event values, 
// they are showing keccak256(event1(uint)) without the values.

null[
  {
    "logIndex": 0,
    "transactionIndex": 0,
    "transactionHash": "0x81979a998ae284933bb890585020692aad9dfa27bf6b8e6425aa2c9affcdfd43",
    "blockHash": "0x5c1f608098236c1eba26b53c872cf379cd3e82079330b2d06d40c6ce4df5811b",
    "blockNumber": 2,
    "address": "0x71ea15737ce3f92e205e3a3dad0263e344d53f24",
    "data": "0x0000000000000000000000000000000000000000000000000000000000000001",
    "topics": [
      "0x84e603adc6c5752ecafe165459551af7ba28bb2e6a2bfacc9ccb8f0ae12c76e6"
    ],
    "type": "mined"
  },
  {
    "logIndex": 1,
    "transactionIndex": 0,
    "transactionHash": "0x81979a998ae284933bb890585020692aad9dfa27bf6b8e6425aa2c9affcdfd43",
    "blockHash": "0x5c1f608098236c1eba26b53c872cf379cd3e82079330b2d06d40c6ce4df5811b",
    "blockNumber": 2,
    "address": "0x71ea15737ce3f92e205e3a3dad0263e344d53f24",
    "data": "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000774657374696e6700000000000000000000000000000000000000000000000000",
    "topics": [
      "0xd61481a11e5449d64f97e1edf49aec06a9ff79cef718c30115a331a73ae49cb4"
    ],
    "type": "mined"
  }
]
0

Events don't really have a "from" address. There are three addresses I can think of that you might mean:

  1. The address of the contract that logged the event.
  2. The address of msg.sender at the time the event was logged.
  3. The address of the externally owned account that initiated the transaction in which the event was logged.

(1) is the address field of the log object you receive.

(2) is not generally available, but many events explicitly include it as part of their data. (E.g., for the contract you mentioned, there's a Transfer event declared as event Transfer(address indexed _from, address indexed _to, uint256 _value);.)

(3) is available by following the transaction hash, which is again part of the log object you receive. Each transaction records its originating "from" address.

  • How come I can see the value of the Transfer event using eth.filter? Isn't it supposed to be a hash of "Transfer(address,address,uint256)" ? – cooldude101 Jan 8 '18 at 22:24
  • I'm not sure I understand. What value? And why wouldn't you be able to see it? All logs are publicly visible. – user19510 Jan 8 '18 at 22:25
  • I thought the topics are hashes of the event name + argument types. Like "Keccak(Transfer(address,address,uint256))", this is what I see when I do we3.eth.filter in remix on testrpc. I'm not seeing the actually values passed to my event. I'm seeing literally only "Keccak(event1(uint))" in "topics" – cooldude101 Jan 8 '18 at 22:29
  • Yes, the first topic is that hash. Did you mean to ask why can't you see some value? Please share your code so someone can help. – user19510 Jan 8 '18 at 22:31
  • The arguments to the event are encoded into the data field. Arguments are only topics if they're indexed, which yours are not. – user19510 Jan 8 '18 at 22:47

Your Answer

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

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