Best way to get old contract data and subscribe for new one

Hey there,

I lost track with the development efforts of AE last months so It’s easier for me to just ask for an advice.

What’s the best way to get old contract data (e.g. get all calls of a specific function between any block height and filter by the input data) and how to get notified when function A is invoked by someone?

The equivalent of that in Ethereum and a lot of other smart contract platforms is the event handling i.e. get all events of a contract for a range of blocks and subscribe for events to get notified in real time.

What’s the best way to accomplish this in AE as I suppose that’s a very common problem that every aepp will need to handle.


The way to do this on aeternity is the same, you would have events logged from your smart contract and subscribe for those or fetch them with middleware.

An (to be improved) example can be found in the governance server.
Manual Fetch:

The middeware/aeternal team did improve the endpoints to do this more easy in the last weeks, these changes are not yet reflected in the governance server yet. But the middlware now supports fetching contract call results, including events, without additional calls neccessary to the node.

The proposed implementation works well and reliable for the governance server.

If you have any more detailed questions let me know.


Thanks mate. Will deep dive into it.

1 Like


I managed to subscribe to events using the above examples that @philipp.chain gave me - thanks.

However I have few issues and suggestions.

  1. When subscribing using the WebSockets of Aeternal (cc: @jsnewby - good job with it) and the message with the transaction data is received I have to call the REST API passing the tx hash to get the event logs. Is it possible to add the event logs to the data passed from the WS? And if it’s possible can you give me some rough ETA? (I’ve added a feature request on github - )

  2. The issue I have is that when I try to get old event data ( from old transactions ) using the Aeternal rest API - e.g.

The result contains no info of the event logs, so I have to make Z number of calls to get the event data (where Z is the amount of transactions returned from the call). So currently there is no viable way to get old event data from a contract. Is it possible to implement such functionality in the foreseeable future?

  1. I think it will be much wiser to improve the endpoint by giving range of blocks - i.e. by given two block heights to get the result of transactions executed between those two blocks. Otherwise, the filtration by blocks need to be implemented on client side, which is very time/memory consuming. Something like this

Thanks in advance!

1 Like

Hi there,

  1. Yes I will do this, I would expect it to happen in the first half this week–it’s not technically demanding and it’s obviously the right thing. I’ll make a new URL for this one, rather than extending the old, to ensure that I don’t break things for existing users. A note one this–I’ll probably make an and corresponding testnet version along with this for new features, since bouncing aeternal disconnects all websocket clients. I’ll share the URL when it’s available.

  2. I am reloading all of the old transactions on testnet (I did this on mainnet already). They should all be reloaded by first thing tomorrow.

  3. Seems reasonable, I’ll try to do it this week too. Could you tell me how you would like the resulting JSON to look?

Thanks for the feedback,


1 Like

Hey @jsnewby thanks for the fast response.

  1. Thanks. So there will be a “new subscription target” similar to this:
      op: "Subscribe",
      payload: "Object",
      target: deployedContractAddr

and the result will include the event logs along with the rest of the tx data? Perfect.

  1. What does this mean? That the event logs are already in the response, only the database need to be refreshed?

  2. I think that the response should be the same as (including the event logs :smiley: ) but only for blocks in the given range.



re: 2–the compiler lost the ability to decode return data (which includes event logs) and then regained it, but with a different interface. So I need to reload the ContractCallTx transactions, which I am currently doing.

I will call the new subscription type ‘TransactionPlus’, which I think sounds good.


1 Like