Can't get events using the Access API

Hello Flow community,

I want to figure out how to fetch all events and transactions for a given block height.
I am trying to do it using the HTTP access API (I’m open to another way too).

First, I get a given block using the /blocks endpoint, e.g. https://mainnet.onflow.org/v1/blocks?height=67524486&expand=execution_result which returns something like this:

...
        "execution_result": {
            "id": "8d0344f1a11f28bb38dca00e43dd7528d41eb927552f3c6e725e152471d5acf1",
            "block_id": "b00fea1c29eb7798d5f8afb6c17972291c0bb888cb445e52068bf6749516f45a",
            "events": [],
            "chunks": [
                {
                    "collection_index": "0",
                    "start_state": "c7z4Cqqa6O94TU3og7hmrrD4bp7nvU34QDAiPXF+bUs=",
                    "event_collection": "6c249640d50bc38d6600c67f4e5064f0fbd24d9d5b8b4f43c4f1e6f4138c60d0",

I notice “events” is always empty here… is that normal?

From here, I noticed “event_collection”, which I suppose is to be fetched using the /collections API. However, this API always gives me a 404, for instance here using the value above, https://mainnet.onflow.org/v1/collections/6c249640d50bc38d6600c67f4e5064f0fbd24d9d5b8b4f43c4f1e6f4138c60d0/

So my questions are:

  1. if I want to find all the info of what happened in a given block, is this approach viable? Am I going in the right direction?
  2. Am I doing something wrong here, to not ever get a proper response to the /collections endpoint?

Thank you in advance for your help!

hi @agardez!

the execution_result result field is actually some metadata about the results from executing the block. As you discovered, it doesn’t contain the data, and the names can be a little confusing. events is a list of “service events” produced during the block. These are for epoch transitions and other protocol level events. event_collection contains the hash of all events emitted during block execution.

The data you’re looking for is available using the gRPC/gRPC-Web endpoints GetTransactionsByBlockID and GetTransactionResultsByBlockID. These will return all transaction payloads and all transaction results (including events) respectively for the entire block.

To query using the REST api, you’ll need to something like:

  • Query the block, expanding the payload /v1/blocks?height=sealed&expand=payload
  • For each collection in the guarantee
    • query to get the tx bodies /v1/collections/[collection_id]?expand=transactions
    • query to get the tx result /v1/transaction_results/[transaction_id]
1 Like

Hi @petera ,
Thanks for your response. I confirm I see the data I’m interested in now with the endpoints you mention.

I want to point out however that the documentation does not mention these endpoints anywhere - they only appear in the protobuf definition on GitHub (I’m glad they exist though! :slight_smile: )

Also, the Python client for the access API is missing them, which is probably related to the above.

Thanks again!

1 Like

Hello @petera ,
This worked well, thank you.

I’m working on indexing historical data for all events across the Flow blockchain. This is so that we can for instance later aggregate the events to compute balances for accounts.

From my understanding there are different endpoints for ranges of block heights, due to the sporks.
I could go ahead and use these different endpoints based on the block height I’m trying to fetch. However I see that there does not seem to be endpoints for before Candidate 4, which starts at block height 1065711.
Is there any way to access the blocks prior to this?

Alternatively, is there some other way to get historical data from the blockchain, such as a cloud bucket of block data exports or database to query?

Lastly, is the state from before mainnet 1 preserved, meaning are there accounts with activity before that, contracts deployed which would still be active?

Thank you