(solved) Quick question about events in sophia

Hi guys,

I’m translating a daepp from Solidity to Sophia and I ran into a problem when trying to use events,
so in solidity I have for example this withdraw event:


And when I try to convert it into my sophia contract like this:


It gives me an error that I have too many indexed fields. I understand why this is happening because
according to the documentation sophia accepts 0-3 index fields in an event.

My first question - Why is that? And how can I bypass this and continue building my daepp? Since I absolutely need more than 3 fields. Is there a workaround for this and how can I implement the event from solidity?

Help would be much appreciated.

@r0b0t0 hey man can you check this out when you’ve got the time :innocent:

Maybe this will be more helpful https://github.com/aeternity/protocol/blob/master/contracts/sophia_explained.md#events

You can have 0-3 indexed fields and a string which ends up in the data field of the event log.

If you need that many info in the event log - best I can suggest is to decide what you need the most to have indexed and the rest you can pack in a string via String.concat

@compiler >= 4

contract MyContract =
  datatype event = Test(bytes(32), bytes(32), bytes(32), string)

  stateful entrypoint emit() =
    let dummy_bytes : bytes(32) = #fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210
    let packed_string : string = String.concat("My data", "more data")
    Chain.event(Test(dummy_bytes, dummy_bytes, dummy_bytes, packed_string))


Aah now I get the idea, thank you so much! :cowboy_hat_face:

1 Like