No Results
Article Image

What's New: Algorand v2.0.7

Algorand v2.0.7 was released to MainNet and TestNet earlier this week. This release was accompanied by an update to the Algorand APIs (v2 API) including a new indexer API (indexer v2) to search data on the blockchain.

What’s New

Indexer v2

The launch of Indexer v2 comes with new functionality to efficiently query data on the blockchain. For example, you can search the note field by prefix, search for accounts that transact with a specific asset, or search for a type of signature (e.g. single sig, multisig, logicsig), just to give a few examples. Browse the full list of features with code examples in each of the SDKs in the Indexer v2 Feature Guide. Make sure to install the indexer first to access these features.

v2 API

This release also comes with some sleek and modernizing updates to the official Algorand SDKs that improve the experience for common functions on Algorand and lay the groundwork for some new features that will come out later this year. Visit the v2 Migration Guide to learn about the major changes. We have also updated the Start Building section with v2 examples to get you started with your first transaction. We will continue to update the documentation feature pages, migrating v1 code examples to v2, and will share updates along the way.

So what is a “sleek and modernizing update”? Let me show you just one of the many improvements in the Python SDK.

How V2 Improves Transaction Creation (Python example)

Every transaction on Algorand requires a set of network-related parameters like the genesis hash, the first and last valid rounds, and the suggested fee. In v1, users fetch these parameters through a suggested_params method call and provide individual values as separate arguments to a transaction maker function (examples). In v2, these suggested network-related parameters are returned as a separate object and supplied as one argument to the transaction maker function.

Let’s look at a simple payment transaction to illustrate this difference. The code below shows the construction of a payment of 1 Algo from Alice to Bob in v2 versus v1. Assume that the client has been instantiated earlier and alice and bob are Algorand addresses. That code will be the same for both.

from algosdk.v2client import algod
from algosdk.future.transaction import PaymentTxn
    # Instantiate params object and give full object to maker function
    params = client.suggested_params()
    unsigned_txn = PaymentTxn(alice, params, bob, 1000000)
from algosdk import algod
from algosdk.transaction import PaymentTxn
    # Pull relevant network params to be supplied to maker function.
    params = client.suggested_params()
    genesis_hash = params.get('genesishashb64')
    first_valid = params.get('lastRound')
    last_valid = first_valid + 1000
    fee = params.get('fee')
    unsigned_txn = transaction.PaymentTxn(alice, fee, first_valid, last_valid, genesis_hash, bob, 1000000)

In the v2 API, we call the suggested_params function and hand its return value directly to the transaction maker function. In the v1 API, we had to handpick each argument from the suggested_params return value and order them as args in the transaction maker function. The advantage to the v2 approach is subtle but important, if we consider that creating a transaction is one of the most common developer user flows on Algorand.

This structure also better aligns with the mental model of distinguishing between transaction fields that are common to all transactions and those that are salient to the specific type of transaction. In this mindset, it not only reduces the amount of code, but also the cognitive load required to create a transaction. This is especially true for the most likely scenario where the suggested parameters are the right parameters.

What if I want to create a transaction offline?

You can always instantiate the SuggestedParams object with your own values if you do not have access to the network or require high customization. See the SuggestedParams object here.

Other Notes

We encourage you to begin migrating your code to v2 and hope you find these updates will improve your overall experience. Code examples throughout the documentation will gradually change to reflect these v2 changes. We will share relevant updates to resources that will help with your migration as they become available.

Stay up to date with the latest developer news by signing up for the Algorand Developer Newsletter.






v2 api

indexer v2

June 18, 2020