Request a specific transaction from the blockchain.

Introduction

For illustration purposes, we’ll request a transaction in the blockchain using the cURL tool information on cURL: Wikipedia

The following code will retrieve a transaction from the Credits blockchain with the given TransactionID :7885122.1 on Testnet.

We are using the “GetTransactionInfo()” function which is explained here: GetTransactionInfo.

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”: “TestNet” - We specify the network, where the request should be executed. Either TestNet or MainNet.

"Compressed": "true" - Here we specify the compression of the information that is send back to us.

“TransactionId”: "7885122.1" - We specify the transaction number which we want to retrieve from the blockchain

"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://apinode.credits.com/api/Monitor/GetTransactionInfo" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"authKey\":\"\",\"networkAlias\":\"TestNet\", \"Compressed\": true, \"TransactionId\":\"7885122.1\",\"methodApi\":\"GetTransactionInfo\"}"

Response

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

{
"id":"7885122.1", - Transaction identifier
"fromAccount":"7CAbMzgimfoHTQy32bJhB3wCx1j3XfZp5TARGMcgp4Fe", //Sender address (public key)
"toAccount":"CZVkVSX7iQVdQpMwV7Pg3j7MmSdKeLEwWdFFjdA7nWc9", //Recipient address (public key)
"time":"2020-06-05T09:40:13.433Z", //Time in UTC format
"value":"0.05244140625", //Transaction amount
"fee":"0.008740234375", //Fee paid for the transaction
"currency":"CS", //Transferred currency
"innerId":101, //Ordinal number of the transaction by sender’s wallet
"index":0, //Ordinal number of the transaction in the block(count from 0)
"status":"Success", //Transaction status, “Success” here means it was successful
"blockNum":"7885122", //Block number, in which the transaction was written
"found":true, //Service parameter indicating that the transaction was found in the blockchain
"userData":null, // userData is missing in this transaction. For example, if this is a smart contract address, this field will contain source code of the smart contract (Try requesting transaction data in MainNet network for the transaction 26144194.1)
Info

In this example, we executed the retrieval of a transaction REST request to the Credits blockchain without any specialized development environment or additional tools.