Algorand developer: Migrate to v2 endpoint plus beginners' guide.

By Ddev | [email protected] | 12 Sep 2020


This post will walk you though how to upgrade to the latest version of Algod client as an existing Algorand developer if you have deployed an application using the algod v1Client as well, it is ideal for quick set up if you are new to the system. Before now, Algorand developers operate using the algod client API - v1 contained in the documentation found here. Later in June this year(2020), Algorand released a new version of the client - v2Client owing to the new improvements. Therefore, existing developers are strongly advised to upgrade their applications to using the v2Client API. 

Alongside the algod v2Client, the indexer was introduced thus as a faucet to enables developers zip through data easily on the Algorand Blockchain. Although it wasn't available in the first version of the Algod client, but it marked a great development in the latest version. However, the changes in v2 does not in any way affect the kmd - Key Management Daemon. The Indexer was developed though part of the chain, but as a standalone, distinct from the main protocol without compromising the scalability purpose of the whole system. Read more about the Indexer. Upgrading requires that you update your preferred SDK to be compatible with the recent version of the client which is contained as the parent class in the SDK - ALGODSK. This tutorial and solution will focus on two of the four development/programming languages available to Algorand developers - Python and Javascript.

Note: I am using DELL computer, window 10 Pro, hence some of the commands used in the documentation might give undesired result. But if you run window OS and follow this guide, it should be sufficient for your need.

Python developers

For existing python developers, type the following code in the CLI: (If you don't already have the algorand python sdk installed, run the same command. It should install the latest algosdk on your machine.

pip install py-algorand-sdk


I already have it installed on my computer, so it showed "Requirement already satisfied" . In your case, it should return a success message.


To confirm if algosdk is installed on your machine, run tthe following command.

pip3 list "py-algorand-sdk"


From the image, I ran same code contained in the reference documentation and I it says 'grep' is not recognized as an internal or external command, operable program or batch file. This is a type of error you're likely to encounter in the process. Now run pip3 list "py-algorand-sdk" . It returns a list of python-related sdks of which you should see py-algorand-sdk. New developers should ensure you have python and pip already installed before attempting to install the algosdk.

Note: In  the earlier version of the py-algorand-sdk, the changes had re-positioned both the algod v1client and kmd to be accessible in version 1.2.1 except for the Indexer, v2Client and kmd are supported by version 1.3.0 .

Using the library

Using version 1.3.0 requires a slight change in the way the library is imported. 



#importing algosdk in previous version

from algosdk import algod

#conneecting to the client requires two parameters if you're running a node or using
#the sandbox or three parameters if you are using a third party service.

#using second option
algod_token = 'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd'
algod_address = '<rest-api-here(visit>'
headers = {X-API-Key: algod_token}

connect_algod_client = algod.AlgodClient(algod_token, algod_address, headers)

Remember the Indexer wasn't implemented in v1

#importing algosdk and Indexer in version 1.3.0

from algosdk.v2Client import algos
from algosdk.v2Client import indexer

#conneecting to the client requires two parameters if you're running a node or using
#the sandbox or three parameters if you are using a third party service.

#using second option
algod_token = 'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd'
algod_address = '<rest-api-here(visit>'
headers = {X-API-Key: algod_token}

connect_algod_client = algod.AlgodClient(algod_token, algod_address, headers)

indexer_client = indexer.IndexerClient(indexer_token, indexer_address)



JavaScrip developers

From the CLI, run the following command. (New to the environment? run the same command to install JS-algorand-sdk.

npm install algosdk


After successful installation, a success message as seen below should pop up.


Check that the installation is successful. 

npm list algosdk

If successfully installed, the terminal will display this.


using the library

//Importing the algosdk in v2 remains same as in previous version.
const algosdk = require('algosdk');

//Specify the token, server amd port to establish connecttion
const algodToken = 'abcdeffedcbaabcdeffedcbaabcdeffedcbaabcdef';
const algodServer = "http://localhost";
const algodPort = 4001;

//Create an instance of the Algod client
let algodClient = new algosdk.Algodv2(algodToken, algodServer, algodPort);

//create an instance of the indexer.
let indexer_Client = new algosdk.Indexer(indexerToken, indexerServer, indexerPort); // new

If you use a third party API such as Purestake, you may need to log on to the user dashboard to get hold of the newly released API. Most time, your token remain unchanged. Ensure you are making use of the right URL.

If you are a beginner, to run the above javascript code, follow this tutorial which also make use the Visual Studio Code. At a point you will need to set up and update the configuration file, you may experience a slight difficulty getting it right. An alternative option that might be of help is to use the following configuration setting provided you have node.js installed.

1.From the top left corner, click on the column to see a drop down. Click on 'Add Configuration'.


2. From list of menu in the drop-down, select 'Node.js: Attach' 




3. The launch.json configuration file should look pretty much like this. To run the code, click on the green triangular shape from the left. It opens a terminal and executes the current file you are working with. ffe36aadfa502c1d336fd6a9a5369a992456ac474b145d1f4b1c1de8c211de75.png


4. Some times, it may not execute automatically, what you need to do is type `node <followed by the name of the file you are working with>`.

That should run perfectly if all things being equal.



There are handful of resources, solutions and tutorials available at your use on Algorand developer website.


How do you rate this article?




I'm a crypto lover, a developer(python, Solidity, Javascript, CSS, HTML), ambassador, blockchain enthusiast and a writer. I am always learning.

[email protected]

A technology company that built and developed the world’s first open, permissionless, pure proof-of-stake blockchain protocol that, without forking, provides the necessary security, scalability, and decentralization needed for today’s economy. With an award-winning team, we enable traditional finance and decentralized financial businesses to embrace the world of frictionless finance.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.