Developers
  • SWT PROTOCOL
    • Introduction
    • Accounts
    • Transactions
    • Fees
    • Smart Contracts
  • GETTING STARTED
    • Network Node
      • Introduction
      • STEP 1:RENTING A LINUX VPS
      • STEP 2:INSTALLATION OF PUTTY
      • STEP 3:INSTALLATION OF FILEZILLA
      • STEP 4:VPS CONNECTION AND LINUX CONFIGURATION WITH PUTTY (SSH)
      • STEP 5:HOW TO SECURE YOUR VPS
      • STEP 6:USING TMUX THROUGH PUTTY
      • STEP 7:UPLOAD OF THE SWT SOFTWARE WITH FILEZILLA
      • STEP 8:EXTRACT THE SWT SOFTWARE FOLDER
      • STEP 9:RUNNING THE SWT NODE THROUGH TMUX
      • STEP 10:RUNNING THE MONITORING TOOLS
  • API REFERENCE
    • Apache Thrift API
      • Transactions
      • Blocks
      • Smart contract
      • Tokens
      • Wallets
      • Sync info
      • Data structures
    • REST API
      • GetBlocks()
      • GetNodeInfo()
      • GetBalance()
      • GetWalletInfo()
      • GetTokenBalance()
      • GetTransactionsByWallet()
      • GetTransactionInfo()
      • GetEstimatedFee()
      • GetContractByAddress()
      • GetContractFromTransaction()
      • GetContractMethods()
      • ContractValidation()
      • ContractCall()
      • TransactionPack()
      • TransactionExec()
  • SMART CONTRACTS
    • Creating "Hello-world" Smart Contract
    • Smart Contract Methods
    • Smart Contract Standarts
      • Token Smart Contract
      • Escrow Smart Contract
      • Stable coin Token
  • HOW TO REST API
    • Introduction
    • Retrieve a balance from the blockchain
    • Request a specific transaction from the blockchain
    • Sending Transactions to the SWT Blockchain
    • Validating and deploying a Smart Contract with REST API
Powered by GitBook
On this page
  • Introduction
  • Description of cURL parameters
  • Code
  • Response
  1. HOW TO REST API

Retrieve a balance from the blockchain

PreviousIntroductionNextRequest a specific transaction from the blockchain

Last updated 1 year ago

Introduction

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

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: .

Description of cURL parameters

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

-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

"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

Wikipedia
Getbalance
Wikipedia
Base58