Retrieve a balance from the blockchain

Introduction

For illustration purposes, we’ll request the wallet balance using the cURL tool information on cURL: Wikipedia

The following code will check the balance of a SWT wallet formatted in Base58 with the given public key “QTRbkssQSGLdKs94khX7i858YcBAhjg6wj48F7FTr8H” used on SWT MainNet.

We are using the “GetBalance” function which is explained here: Getbalance.

Description of cURL parameters

-X POST - type of HTTP request, in this case we use POST. More info here: Wikipedia

-H “accept: application/json”

-H “Content-Type: application/json” - Specification for the transferred parameters and response to be in JSON format

-d {parameters} - With this key, we specify the data transferred with the request. Let’s look at them in more detail:

“authKey”: “” - Authorization key. Not used at present, should be passed “”

“networkAlias”: “MainNet” - We specify the network, where the request should be executed. Either TestNet or MainNet.

“PublicKey”: “QTRbkssQSGLdKs94khX7i858YcBAhjg6wj48F7FTr8H” - We specify wallet address (public key) in Base58. More on Base58

"methodApi": "GetBalance"

Warning

For CMD to overlook quotation marks “ inside the request body since those are special characters, they should be escaped with the backward slash.

Code

Let's try it out with the following code !

curl -X POST "http://176.113.80.7:62000/api/Monitor/GetBalance" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"authKey\":\"\",\"networkAlias\":\"MainNet\", \"PublicKey\":\"QTRbkssQSGLdKs94khX7i858YcBAhjg6wj48F7FTr8H\",\"methodApi\":\"GetBalance\"}"

Response

We get the following response from the REST API in JSON.

{
   "balance":78986512.126207759516370000,
   "tokens":[],
   "delegatedOut":0,
   "delegatedIn":0,
   "success":true,
   "message":null
}

Info

In this example, we executed the simplest REST request to the SWT blockchain without any specialized development environment or additional tools.

Here we see the wallet balance to be 78986512.126207759516370000 SWT which matches the monitor data

Last updated