Exploring the Public API Docs of Block.io

Block.io is a cryptocurrency wallet API that works across multiple networks, including Bitcoin, Litecoin, and Dogecoin. In this blog post, we will explore the public API documentation of Block.io and how to use it in JavaScript.

Getting Started

Before we dive into the code, we will need to sign up for an API key on the Block.io website. Once you have created an account, you will receive an API key that we will use to authenticate our requests.

Block.io provides RESTful API endpoints to interact with the wallet API. The base URL for the API is https://block.io/api/v2/ and to access a particular endpoint, we will append it to the base URL.

Example Code

Creating a New Address

To create a new address, we will make a POST request to the /get_new_address endpoint. Here's the example code in JavaScript:

const axios = require('axios');

const apiKey = 'YOUR_API_KEY';
const baseURL = 'https://block.io/api/v2/';
const endpoint = 'get_new_address';

axios.post(`${baseURL}${endpoint}`, {
  api_key: apiKey,
  label: 'My New Address'
}).then(response => {
  console.log(response.data);
}).catch(error => {
  console.error(error);
});

In the code above, we are using the axios library to make an HTTP POST request to the /get_new_address endpoint. We are providing the api_key and label parameters as options in the request body.

Getting the Balance of an Address

To retrieve the balance of an address, we can make a GET request to the /get_balance endpoint. Here's the JavaScript code to do that:

const axios = require('axios');

const apiKey = 'YOUR_API_KEY';
const baseURL = 'https://block.io/api/v2/';
const endpoint = 'get_balance';
const address = 'ADDRESS_TO_CHECK_BALANCE';

axios.get(`${baseURL}${endpoint}`, {
  params: {
    api_key: apiKey,
    address: address
  }
}).then(response => {
  console.log(response.data);
}).catch(error => {
  console.error(error);
});

In the code above, we are using the axios library to make an HTTP GET request to the /get_balance endpoint. We are providing the api_key and address parameters as query parameters in the URL.

Conclusion

Block.io provides a simple and easy-to-use API for interacting with cryptocurrency wallets. In this blog post, we explored the public API documentation of Block.io and how to use it in JavaScript. We covered two examples of making requests to the API to create a new address and retrieve the balance of an existing address.

Related APIs in Cryptocurrency