I am trying to emit an Event with UUIDv4 indexed
string
.
Example contract:
contract EventEmitter {
event ExampleEvent(string indexed id);
function dispatchEvent(string memory _uuid) public {
emit DebugEvent(_uuid);
}
}
Because string
can have an arbitrary length, Solidity creates a Keccak-256 hash of the value which ends up in the topic.
for UUID 85abe432-538e-4281-8697-85e18775df5c
the value is 0xd4796a1ffda94665a2d19bf19cb326dabce44288e3a53d53a2b60f4c9f411650
So when I'm retrieving past events using web3, I'm unable to get the correct string value
I found this question Bytes16 event topic not being decoded (or encoded?) correctly
Where UUID is represented as bytest16
.
However I couldn't find a straightforward way to convert a string
into bytes16
.
Would appreciate any help.
-
), convert the hex characters to its byte1 equivalent, you should have 16 bytes1, after concatenating you have a bytes16.