Event subscription

Hello again.

Is it currently possible to fire an event and then subscribe for it from the SDK (or poll for the results). If so, can you be please so kind to tell me how.

I know the official middleware has websockets to which you can subscribe and it will inform you of changes in states.

But this is not part of the main node. you could check if the middleware helps you with this GitHub - aeternity/aeternal: Æterrnal--the caching and reporting layer for the æternity blockchain

Hey, thanks for answering. I know about the middleware, but the description of the websockets leads me to the conclusion that the event listening is not supported. And that’s why I am asking for an example.

The middleware permits you to subscribe to events via a websocket, and receive updates when the chain state changes. Currently you can subscribe to key blocks, micro blocks, and soon to all events involving a particular on-chain object (contract, account, ...).
1 Like

As it says, you can currently subscribe to keyblocks and microblocks.

And I don’t need that. That’s why I opened this thread. Can anyone actually provide me an answer?

do you mean events in smart contracts? then yes, this is possible and documented here:

regarding the SDK supporting subscription. I assume this is not available ATM. but I think @noandrea can answer this question best :slight_smile:

Yes, I want to subscribe or read past events fired from the smart contract.

Hi,

It’s nice to meet you guys.

Hey @kraykov we will answer shortly, thanks.

Still waiting for an answer.

Hello @kraykov, the middleware does not support subscription to events and indexing yet. This shouldn’t keep you from using them though, the node can return all emitted events for a call via the transactions/{tx_hash}/info endpoint.

@philipp.chain How can I do that without knowing the tx hash? Because if I know the tx hash I wouldn’t need the event info.

why don’t you know the transaction hash for a transaction you did?

If you need to find a transaction hash you want to consider you can do this using the middleware.

Okay, if you are going to ask me questions on something we have thought about for a long time I’ll directly give you the use case and then maybe you can give me better directions how to accomplish it.

The use case:

  1. There are 100 active users
  2. One user makes an action after which the other 99 users needs to be notified.

Long polling on the client side is not an option, because it will take the node down (let’s assume it’s not 100 but 100 000)

1 Like

Sounds like this is not a task that is to be solved by using a blockchain protocol but some indexing infrastructure.

I would advise you to use a trustless backend for this task, that takes care of indexing and notifying and is probably connected via websockets.

Exactly. That’s why I need event subscription or a possibility to read past events (without using tx hash)

what keeps you from building this? index your transactions, then create your interface to subscribe to.

/transactions/{tx_hash}/info provides you the information from events.

Because that’s not the correct way of doing this. This will create a lot of attack vectors, that can be avoided by simply having an event subscription. Or at least reading all transactions made to a certain contract (maybe at certain block height).

where would you suggest this event subscription to be made? why should this provider be less of an attack vector than having a backend?

Because the service will subscribe for events independently from the client. Clients will subscribe for events using that “backend” service therefore the data will be always correct because:

  1. users cannot interfere with the “backend” service
  2. the service will read the data directly from the network only once for every user.