How can I get the archived events with Dazl?

I’m trying to get all the create and archive events from the transaction stream using the following function (I don’t need asyncio.run() because I’m running it on Google Colab):

async def get_events(template_id):
  async with dazl.connect(**env) as conn:
    async with conn.query(template_id) as stream:
      async for event in stream.events():
          print(event)

await get_events('*')

My understanding of the Dazl docs is that this should return both the create and archive events. I know that I have archived contracts on the ledger. But instead of all the events, I get returned only the create events:

<dazl.ledger.api_types.CreateEvent object at 0x119d26770>
<dazl.ledger.api_types.CreateEvent object at 0x1197dcc20>
<dazl.ledger.api_types.CreateEvent object at 0x119d26770>

What am I doing wrong?

query first returns the active contract set, and then additional changes that happen over the transaction stream once you’ve fully caught up. This is the default behavior because streaming over all events from the beginning of time can be quite expensive. In addition, eventually long-running ledgers will need to be pruned, in which case you can’t count on the active contract set to be wholly derived off of individual events that you can observe.

If you want to observe “recent” archive events, you can pass an offset parameter into query that specifies where to start. Offsets come on every Boundary, which you can obtain by iterating directly over the stream (so in other words, async for event in stream as opposed to async for event in stream.events()).

1 Like

Thanks, will try that!