Using the SDKs and REST APIs

Overview

Every Algorand node has two basic processes that a developer can interact with to build applications that work in conjunction or on top of the Algorand blockchain. These processes are the key management daemon (kmd) and the Algorand protocol daemon (algod). The kmd is primarily responsible for key management and signing of transactions. This process can also run on separate machines for maximum security. The kmd provides an API that can be used to create new keys, update existing ones and sign transactions. The kmd is primarily intended for Wallet developers but can also be used to sign transactions to be posted to the Algorand network. The algod process handles processing the protocol, proposing blocks, interacting with the ledger, and building voting committees. The algod process also provides an API that retrieves information about the blockchain, like specific transactions, blocks, and network status.

The kmd and algod processes also serve their respective APIs using REST servers. These APIs are described using the Open API Specification version 2 (OAS 2). Each process provides this specification in a swagger.json file that is available from the process by using the REST API call: 

curl localhost:8080/swagger.json 

Note: The kmd process is currently not serving the swagger.json file. This will be enabled in the next TestNet uplift. To get the swagger file for kmd now just copy the contents from here.

In the above example, the host will be the server that the process is running on and the port is the configured REST endpoint. This endpoint is stored in a file within the data directory for the algod process and in the kmd directory for the kmd process. The name of the file is algod.net and kmd.net respectively. See the node configuration parameters if you wish to change these endpoint ports.

Security Token

Most REST calls will also require an API token header in order 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 is located in the data directory and named algod.token. For the kmd process, the file is stored in the kmd directory and named kmd.token. You can manually generate the token as well with a goal command.

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

You can include these tokens when making the calls from a REST client. To do this with curl use 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.

Client SDKs

In addition to REST APIs we are currently building a set of client libraries in other languages like Go and JavaScript. These libraries are intended to be task-oriented SDKs to quickly integrate with projects in common languages. Currently, the Go SDK and JavaScript SDK are available.