SDKs

Overview

Algorand provides supported SDKs for JavaScript, Python, Java and Go. These SDKs offer both standalone and node connected functionality. The node connected functionallity is designed to use the REST endpoints, described below, for the primary Algorand node processes. The stand alone functions offer capabilities for offline or limited connected operation. These offline functions include the ability to work with accounts that are not managed by by Algorand key management daemon(kmd) and to work with transctions. This includes creation, signing and appending signatures to transactions. Support is also provided for multisignatures and logic signatures.

Examples of using the SDKs are provided throughout the developer website. Additional examples are also provided within the individual repository locations. Additional developer reference documentation is described below.

Rest Endpoints

Integration with either the Algorand protocol daemon (algod) or the Algorand key management daemon (kmd) is provided using a set of REST APIs. These APIs are described using the Open API Specification version 2 (OAS 2). Each of these processes serves their respective API on a separate port and url which is stored in the algod.net and kmd.net files within the data and data/kmd-version directories. Each process provides the specification in a swagger json format that is available using the following REST API calls:

Algorand Protocol Daemon

curl http://$(cat ~/node/data/algod.net)/swagger.json

Algorand Key Management Daemon Assuming data directory is ~/node/data

curl http://$(cat ~/node/data/kmd-v0.5/kmd.net)/swagger.json

Info

The kmd process is only automatically started when using goal commands that access the kmd. This process will also timeout after 60 seconds of being idle. If you require SDK access to the kmd you will need to manually start the process with goal using the command: goal kmd start -d <data-dir>.

All algod REST methods and models are decribed in the algod reference documentation. All kmd REST methods and models are decribed in the kmd reference documentation.

Security Token

Most REST calls will also require an API token header to make calls against the REST server. This token is generated by the process and is stored in a file. For the algod process, the file (algod.token) is located in the data directory. For the kmd process, the file (kmd.token) is stored in the data/kmd-version kmd. Security tokens can be regenerated using the goal node generatetoken command.

The API Token for the algod process is named X-Algo-API-Token and the kmd's is named X-KMD-API-Token.

Each of the SDKs provides a method for setting these headers. Most REST tools provide a method for setting additional headers. To set the header with a curl command use the the -H parameter. For example to make a call to retrieve a specific block, use the following curl command from a terminal in the data directory.

curl http://$(cat algod.net)/v1/block/31538 -H "X-Algo-API-Token: $(cat algod.token)"

In the above example, the block information will be displayed if the block exists on the local node. If the node is a non-Archival node, older blocks will not be available.

JavaScript

Installation

The JavaScript SDK is available as NPM package or as minified JavaScript library. The SDK is installed for usage with a Node project using npm.

Node.js

$npm install algosdk

To install the minified library, download the library and add it to the project's library location. Use the src tag to specify the location of the library.

<script src="algosdk.min.js"/> 

The GitHub repository contains additional documentation and examples.

Python

Installation

The Python SDK is available with the Python Package Installer (pip). The SDK requires Python3 be installed. To install the SDK, open a terminal and run the following command:

$pip3 install py-algorand-sdk
Alternatively, choose a distribution file, and run

$ pip3 install [file name].

The GitHub repository contains additional documentation and examples.

See the Python SDK reference documenation for more information on methods.

Java

Installation

The Java SDK is available in Maven’s central repository and can be used in your Maven project by using the following dependency.

<dependency>
    <groupId>com.algorand</groupId>
    <artifactId>algosdk</artifactId>
    <version>1.2.1</version>
</dependency>

The Java SDK requires Java 7+ and Android minSdkVersion 16+.

The GitHub repository contains additional documentation and examples.

See the Java SDK reference documenation for more information on packages and methods.

Go

Installation

The Go SDK is provided as a standard go package and can be downloaded and installed using the go get command as shown below:

go get -u github.com/algorand/go-algorand-sdk/..

The GitHub repository contains additional documentation and examples.

See the Go SDK reference documenation for more information on packages and functions.