Handling contract events from js sdk

Hello everyone,

I’m building a daepp and currently I’m stuck on trying to test my Events in the js sdk.

my Event is something like this:

datatype event =
Withdraw(indexed bytes(32), indexed address, indexed address, string) | ...

And I’m emitting it as follows:

Chain.event(Withdraw(id, state.contracts[id].sender,
 state.contracts[id].receiver, bundle_string ))

I need to get all of that info once the event has been fired, in my js sdk file.

How can I catch the event though? I just need a simple example.

Thanks in advance :grin:

@philipp.chain , @milenradkov.chain if you guys have a sec? :sweat_smile:

There is no such functionallity out of the box. Aeternal (Middleware) has helpers for some parts of what you want, but I don’t have an example ready.

Otherwise you can also use websockets from Aeternal (Middleware) to listen to your contract. Then read the event information manually.

Your event name will be storred hashed, so you have to decode it. E.g. const hashTopic = topic => blake2b(32).update(Buffer.from(topic)).digest('hex'); in JS.

1 Like