Making API Calls

Making calls to the Radix Node API is simply sending an HTTP request with to the URL of a specific endpoint and method, with some JSON input data, and receiving a response. A simple way to test the API is to use an HTTP client. Postman provides a nice client for exactly this purpose, as do many developer IDEs. For simplicity, in the example below we’ll simply use curl.

To make an API call, you will need to specify a node to make the request to. If you are a node-runner using one of the private API endpoints for node operation, this is your node’s own IP with the port you’ve configured for the endpoint in question.

Most developers however will be mostly interested in the /archive and /construction endpoints offered by archive nodes for queries on ledger data and making transactions. For experimenting with these endpoints, Radix offers load-balanced archive nodes on port 443 of https://mainnet.radixdlt.com. We will use this for our examples.

If you want dedicated endpoints for your own use or application, we recommend you install and configure your own archive node that can offer them.

A simple API query example

Let’s start with a query to a simple info method on the /archive endpoint without any parameters: tokens.get_native_token. This query asks for information about the native token of the Radix network (which of course we expect to be XRD).

We can check the Node API Postman specification to find the expected JSON input to the /archive endpoint for this method. We make the call by including the JSON input in a curl command (and a little python to parse the output) as follows:

A call to the /archive/tokens.get_native_token method
curl -d '{
    "jsonrpc": "2.0",
    "method": "tokens.get_native_token",
    "params": [],
    "id": 1
}' -H "Content-Type: application/json" -X POST "https://mainnet.radixdlt.com/archive" | python -m json.tool

If all goes well, you should receive a response like this:

Response to the /archive/tokens.get_native_token call
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "currentSupply": "30015626048229400000000000000",
        "description": "Radix Tokens",
        "granularity": "1",
        "iconURL": "https://assets.radixdlt.com/icons/icon-xrd-32x32.png",
        "isSupplyMutable": true,
        "name": "Rads",
        "rri": "xrd_rr1qy5wfsfh",
        "symbol": "xrd",
        "tokenInfoURL": "https://tokens.radixdlt.com/"
    }
}

The result includes all of the various pieces of metadata you might want to know about XRD, Radix’s native token.

One particularly interesting bit of info is the rri. This is the "radix resource identifier" of the token. All tokens created on Radix have an rri that you can use with a different API method: tokens.get_info.

Let’s use the rri of the XRD token to try out this method to see what it’s like to pass a parameter to an API endpoint method:

A call to the /archive/tokens.get_info method
curl -d '{
    "jsonrpc": "2.0",
    "method": "tokens.get_info",
    "params": {
      "rri": "xrd_rr1qy5wfsfh"
    },
    "id": 1
}' -H "Content-Type: application/json" -X POST "https://mainnet.radixdlt.com/archive" | python -m json.tool

You should receive a result very similar to the tokens.get_native_token method – but this one you can use with any token rri that you find on the Radix network.

Now that you’ve done a simple query, you might want to proceed on to learning how to make transactions using the Node API.