Overview

About blockchain APIs

A blockchain API is a set of programming interfaces that allow developers to access the functionality of a blockchain from within their applications. It enables external programs to interact with the blockchain, read or write data, and execute smart contracts.

👍

Get you own node endpoint today

Start for free and get your app to production levels immediately. No credit card required.

You can sign up with your GitHub, X, Google, or Microsoft account.

A blockchain API allows developers to build applications that can read or write data to the blockchain or that can execute smart contracts (which are self-executing contracts in which the terms of the agreement between buyer and seller are directly written into lines of code).

📘

A developer can use a blockchain API to build a decentralized exchange, a block explorer, or a supply chain management platform.

Blockchain APIs are an essential part of the blockchain ecosystem, enabling developers to build and integrate new applications with existing ones. They allow different software to communicate with the blockchain and with each other.

About this reference

Node API

A collection of articles that explain how the most popular API methods work on the following networks:

Each method has a detailed explanation, a real use case, and an interactive window to try it out.

Chainstack platform API

The Chainstack platform API allows you to manage:

  • Your organization
  • Your projects
  • Your networks
  • Your nodes
  • Your identities

To start with the API, you must create an API key.

For all available API operations, see API reference.

Getting started

Follow these steps to sign up on Chainstack, deploy a node, and find your endpoint credentials:

  1. Sign up with Chainstack.
  2. Deploy a node.
  3. View node access and credentials.

Make your first request

Chainstack's infrastructure allows you to access and retrieve data from a blockchain using JSON-RPC and the command line.

To make manual requests, it's recommended to use tools such as curl or Postman and send POST requests via JSON-RPC.

The following is an example of a curl request that interacts with a Chainstack node's JSON-RPC API.

curl -X POST "CHAINSTACK_NODE_URL" \
  -H 'Content-Type: application/json' \
  --data '{"method":"eth_blockNumber", "jsonrpc":"2.0", "params":[],"id":1}'

The request consists of the following:

  • curl -X POST which is used to initiate a POST request to the specified URL, a Chainstack node in this case; CHAINSTACK_NODE_URL.
  • -H 'Content-Type: application/json' specifies that the request's content type is in JSON format.
  • --data '{"method":"eth_blockNumber", "jsonrpc":"2.0", "params":[],"id":1}' is the request's payload, which contains the JSON-RPC request data.

The payload of the request contains the following fields:

  • method — defines the method that is being called, in this case, eth_blockNumber.
  • jsonrpc — defines the version of the JSON-RPC protocol in use; it is set to 2.0.
  • params — is used to pass any additional parameters required by the method; in this case, it is empty.
  • id — is used to identify the request. It is set to 1 in this case, and you can use id to identify the request the response belongs to.

This request is asking for the latest block number in the blockchain. The method eth_blockNumber will return the number of the most recent block in the chain.

Response example:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x24655cf"
}

📘

Find different ways to interact and retrieve data from the blockchain in the Web3 libraries and tools guide.

Password-protected access

For the blockchain API requests, you can also use basic authentication:

  • HTTPS endpoint: https://ethereum-mainnet.core.chainstack.com
  • WSS endpoint: wss://ethereum-mainnet.core.chainstack.com/ws
  • Username: YOUR_USER_NAME
  • Password: YOUR_PASSWORD

📘

You can find your username and password credentials in the Chainstack console.

For password-protected access, you include the username and password in your curl command like so:

curl -X POST \
  -u YOUR_USER_NAME:YOUR_PASSWORD \
  -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":1}' \
  https://ethereum-mainnet.core.chainstack.com

In this command, -u YOUR_USER_NAME:YOUR_PASSWORD includes your username and password for basic authentication. Please replace YOUR_PASSWORD with your actual password.