VCS API Documentation
VeChain Stats
  • Introduction
  • Getting Started
    • 🗝️Getting an API Key
    • 🔓Authentication
    • 📬Postman
    • ✳️Swagger
  • API Endpoints
    • Account
      • Account Stats
      • ✨Account Extended Stats
      • Account Info
      • ✨Account VTHO Info
      • VET/VTHO Balance
      • ✨Transactions In
      • Transactions Out
      • ✨Token Transfers
      • ✨NFT Transfers
      • ✨DEX Trades
      • DEPRECATED: Internal Transfers
      • Historic VET/VTHO
    • Token
      • Token List
      • Token Info
      • Token Price
      • ✨Token Price List
      • Token Supply
      • ✨VIP180 Balance
      • VIP180 Balance Custom
      • ✨Token Holder List
    • Transaction
      • Transaction Status
      • Transaction Info
    • Block
      • Block Daily Stats
      • Block Info
      • Block Height
      • Block by reference
      • Block by timestamp
    • Contract
      • Contract Stats
      • Contract Info
      • Contract Code
    • NFT
      • NFT Token List
      • NFT Info
      • ✨VIP181 Balance
      • VIP181 Balance Custom
      • ✨NFT Holder List
    • Carbon
      • Address Emission
      • Block Emission
      • Transaction Emission
      • Network Emission
    • Network
      • Network Totals
      • Network Stats
      • Network Gas Stats
      • Authority Nodes
      • ✨Mempool
      • Node Token Count
      • ✨Node Token Stats
      • Thor Instance Size
      • X-Node List
    • API Info
      • API Info
      • API Ping
  • Support
    • FAQ
    • Rate Limits
    • Response HTTP Status
    • Common Error Messages
    • Socials
    • Change Log
  • Visit VeChain Stats
Powered by GitBook
On this page

Was this helpful?

  1. Getting Started

Authentication

PreviousGetting an API KeyNextPostman

Last updated 1 year ago

Was this helpful?

Utilizing Your API Key

To interact with the VeChainStats API, you have the flexibility to employ any server-side programming language capable of making HTTP requests. All requests must be directed towards the domain You have two options for incorporating your API Key into REST API calls:

  1. Preferred approach: Through a dedicated custom header named X-API-Key.

In your application, you need to add the API Key to the header of your requests for authentication. Below we provide some code examples to add the API Key to the header in different environments:

curl -X GET "https://api.vechainstats.com/v2/network/totals" -H "X-API-Key: YOUR_API_KEY_HERE"
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class APIClient {
    public static void main(String[] args) {
        try {
            String apiKey = "YOUR_API_KEY";
            String apiUrl = "https://api.vechainstats.com/v2/network/totals";

            URL url = new URL(apiUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();

            // Set the request method to GET
            connection.setRequestMethod("GET");

            // Set the API Key header
            connection.setRequestProperty("X-API-Key", apiKey);

            // Read the response
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String inputLine;
            StringBuilder response = new StringBuilder();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }

            // Close the connection and print the response
            in.close();
            System.out.println(response.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
const https = require('https');

const apiKey = 'YOUR_API_KEY';
const apiUrl = 'https://api.vechainstats.com/v2/network/totals';

const options = {
  method: 'GET',
  headers: {
    'X-API-Key': apiKey,
  },
};

const req = https.request(apiUrl, options, (res) => {
  let data = '';

  res.on('data', (chunk) => {
    data += chunk;
  });

  res.on('end', () => {
    console.log(data);
  });
});

req.on('error', (error) => {
  console.error(error);
});

req.end();
package main

import (
	"fmt"
	"net/http"
	"io/ioutil"
)

func main() {
	apiKey := "YOUR_API_KEY"
	apiURL := "https://api.vechainstats.com/v2/network/totals"

	req, err := http.NewRequest("GET", apiURL, nil)
	if err != nil {
		fmt.Println(err)
		return
	}

	req.Header.Set("X-API-Key", apiKey)

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(string(body))
}
import requests

# Set your API Key as a variable
API_KEY = "YOUR_API_KEY"

# Define the API endpoint
api_url = "https://api.vechainstats.com/v2/network/totals"

# Set the headers with the API Key
headers = {
    "X-API-Key": API_KEY
}

# Make a GET request to the API
response = requests.get(api_url, headers=headers)

# Print the response
print(response.text)
<?php
$API_KEY = 'your_api_key_here';
$url = 'https://api.vechainstats.com/v2/network/totals';

// Initialize cURL session
$ch = curl_init($url);

// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return output as string
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "X-API-Key: $API_KEY"
));

// Execute the cURL session and fetch the data
$response = curl_exec($ch);

// Check for cURL errors
if(curl_errno($ch)) {
    echo 'cURL error: ' . curl_error($ch);
} else {
    // Decode JSON response
    $data = json_decode($response, true);

    // Print the response
    print_r($data);
}

// Close the cURL session
curl_close($ch);
?>

Replace "YOUR_API_KEY" with your actual API key.

  1. Convenience method: By including it as a query string parameter named VCS_API_KEY.

Example request:

https://api.vechainstats.com/v2/account/vet-vtho
    ?address=0xd0d9cd5aa98efcaeee2e065ddb8538fa977bc8eb
    &VCS_API_KEY=YOUR_API_KEY

Replace YOUR_API_KEY with your actual API key.

Security Alert: Safeguarding your API Key from public exposure is of utmost importance. For operational environments, it is strongly advised to utilize the custom header option instead of the query string method when transmitting your API Key.

🔓
https://api.vechainstats.com/v2/
.