Skip to content

how to parse string indexed from event #2909

Answered by zemse
yashtbc asked this question in Q&A
Discussion options

You must be logged in to vote

The event indexing works by having a upto 4 bytes32 topics which can be included in the filter. A string value is dynamic and doesn't fit in bytes32 so solidity hashes it so it fits in the bytes32. Basically getting the username param would be finding the preimage of the hash function, which doesn't seem something you can do with keccak256 practically.

You may switch the string type to bytes32, it will limit the username to 32 length (which can be reasonable). If it's necessary to stick with string you can include it again.

event Lock(address indexed user, uint256 amount, string indexed usernameTopic, string username);

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by yashtbc
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants