Create Publication

We are looking for publications that demonstrate building dApps or smart contracts!
See the full list of Gitcoin bounties that are eligible for rewards.

Article Thumbnail

Introducing Algorand’s V2 Indexer

Searching for transactions and other blockchain data points can be difficult, to say the least. It is not only extremely time consuming but often blockchains restrict the amount of information that can be searched in one operation. While this does help the blockchain nodes to run more efficiently, it can be frustrating trying to create applications that make use of the ledger data. Algorand’s approach to this issue was to offer an indexer property for Algorand nodes. This property, when enabled, allowed additional metadata to be stored with the ledger data for searching purposes. While this approach works nicely, the number and types of searches were restrictive. To circumvent these restrictions, Algorand redesigned the Indexer and moved it to its own process, separating it from the node altogether. This V2 Indexer is available now!

You can read about how to install the new Indexer in the Setup Guide. For descriptions on all the REST API endpoints available, see the Indexer Feature Guide.

The new Indexer supports searching for transactions, accounts, assets, and blocks. In addition, these searches can be refined using parameters that allow searching based on transaction and balance amounts, time-based searches, round-based searches and transaction type searches, and signature searches.

For example, if I want to find out information about a specific Algorand Asset like the DevDocsCoin, I can search for it by name.

 curl "localhost:8980/v2/assets?name=DevDocsCoin" | json_pp
{
   "assets" : [
      {
         "params" : {
            "reserve" : "SWOUICD7Y5PQBWWEYC4XZAQZI7FJRZLD5O3CP4GU2Y7FP3QFKA7RHN2WJU",
            "name" : "DevDocsCoin",
            "creator" : "SWOUICD7Y5PQBWWEYC4XZAQZI7FJRZLD5O3CP4GU2Y7FP3QFKA7RHN2WJU",
            "clawback" : "SWOUICD7Y5PQBWWEYC4XZAQZI7FJRZLD5O3CP4GU2Y7FP3QFKA7RHN2WJU",
            "decimals" : 0,
            "default-frozen" : false,
            "total" : 1000000,
            "manager" : "SWOUICD7Y5PQBWWEYC4XZAQZI7FJRZLD5O3CP4GU2Y7FP3QFKA7RHN2WJU",
            "url" : "https://bit.ly/374zKN2",
            "freeze" : "SWOUICD7Y5PQBWWEYC4XZAQZI7FJRZLD5O3CP4GU2Y7FP3QFKA7RHN2WJU",
            "unit-name" : "HiWorld"
         },
         "index" : 2044572
      }
   ],
   "current-round" : 7167266
}

Using the index from this call I can now search the Ledger for any accounts that own this token by using the following REST endpoint.

$ curl "localhost:8980/v2/assets/2044572/balances" | json_pp
{
   "balances" : [
      {
         "amount" : 999900,
         "address" : "SWOUICD7Y5PQBWWEYC4XZAQZI7FJRZLD5O3CP4GU2Y7FP3QFKA7RHN2WJU",
         "is-frozen" : false
      },
      {
         "address" : "UF7ATOM6PBLWMQMPUQ5QLA5DZ5E35PXQ2IENWGZQLEJJAAPAPGEGC3ZYNI",
         "is-frozen" : false,
         "amount" : 100
      }
   ],
   "current-round" : 7167317
}

Many additional criteria can be added to refine the searches with the new Indexer. This includes many calls supporting historical based searches that all you to do things like searching for balances of an asset or Algos at a specific round in the past.

The Indexer also provides a results pagination mechanism that allows searches to be efficiently split into many REST calls without adding extra load on the server This feature allows you to set the size of the paginated result and put your application in control of how and when you want to process the results.

All transactions on the Algorand network are allowed to add up to a 1kb note to each transaction. This can be very useful when building layer 2 applications, for storing additional metadata. The indexer now provides a searching mechanism that allows you to search these notes for a specific byte prefix. This can be used as a very simple way for applications to tag specific transactions and quickly return a list of these transactions.

All of the Algorand SDKs have been updated to fully support the new Indexer, so make sure to update your SDK and let us know what you think about the new capabilities. Stay tuned for more great features to land on the Algorand network over the coming weeks. To make sure you stay on top of these developments, signup for the developer newsletter!