Guide: How to Develop Web3 DApps on Bitcoin Network Using NFTScan NFT API

NFTScan
NFTScan
Published in
7 min readMay 21, 2024

On May 16, 2024, the NFTScan team officially upgraded the Bitcoin NFT explorer. This upgrade included a comprehensive upgrade of the Ordinals inscription section, optimizing NFT data parsing and transaction parsing functions from different trading markets.

Currently, the NFTScan developer platform has also synchronized the Bitcoin network’s NFT API data service, in addition to multiple API query interfaces that were previously open to the public. As a foundational infrastructure for NFTs in the Bitcoin ecosystem, NFTScan will continue to develop features and services to provide high-quality NFT API data services and wallet address NFT asset data search services for developers and NFT users within the Bitcoin ecosystem.

The comprehensive upgrade of Ordinals data includes but is not limited to:

  • Fully optimizing the NFT data parsing system based on the latest protocol from Ordinals, ensuring accurate and complete inscription data.
  • The added inclusion of official collection information from UniSat and OKX enriches the Collection dimension.
  • Added transaction market transaction parsing, distinguishing NFT inscription buy and sell events from UniSat, OKX, and MagicEden.

This upgrade also added the “Retrieve BRC-20 Tick”, “Retrieve BRC-20 Balances”, and “MerlinProtocol BRC-20 Indexer” series of API interfaces to meet various indexing needs for NFT data in different scenarios.

How to access NFTScan NFT API

  1. Create an NFTScan developer account

Before using the NFTScan API, you need to visit the developer website and create an account. Go to the NFTScan official website and click on the NFTScan API “Sign Up” to start your API journey.

NFTScan Developer Platform

After logging in, find your unique API KEY on the Dashboard and copy it. Visit the API documentation, input your API key into the appropriate place in the API documentation, and follow the instructions in the documentation to start using the API services. In the API documentation, developers can find various interface modes to choose from based on their needs.

In the Dashboard, developers can also view statistics of their API usage, helping to keep track of historical usage data. Additionally, NFTScan provides 1M CU of API call service for each registered developer, which can be used to request all NFT API interfaces, and the CU never expires until it is used up.

View Bitcoin NFT API documentation

After successfully registering a developer account and obtaining an API Key, you need to view the NFTScan API documentation. The API documentation includes all available API endpoints, parameters, and detailed information on how to build requests and handle responses. Read the API documentation carefully and make sure you understand how to use the API to retrieve the data you need.

NFTScan currently has the largest and most comprehensive NFT Collection library, supporting full NFT data for 24 blockchains including Ethereum, Solana, BNBChain, Bitcoin, TON, Polygon, and many others. The API offers a range of interfaces to access ERC721/ERC1155/ERC20 assets, transactions, projects, market statistics, and more, now supporting over 60 public interfaces for EVM-compatible chains, as well as interfaces for Solana, Aptos, Bitcoin, and TON.

Bitcoin API Models

The main Bitcoin API models include the following three interfaces with an overall introduction and explanation of some core API fields to help developers understand how to retrieve data and utilize this information for their DApp services.

  • Assets API: This API provides key data fields in NFTs for unique identification and description of digital assets.
  • Transactions API: This API represents the full transaction data of an NFT asset on the blockchain, allowing developers to understand the complete lifecycle of NFT assets within the BTC ecosystem.
  • Collections API: This API retrieves information related to NFT Collections such as descriptions, social media, and other basic data.

Added Bitcoin API series

  1. Retrieve BRC-20 Tick series
  • Get a BRC-20 tick (returns information on a BRC-20 tick)
  • Search BRC-20 ticks (returns a list of BRC-20 ticks based on a search filter in the request body)

For example, by using the Get a BRC-20 tick interface for “/btc/brc20/tick/{tick}”, you can retrieve detailed information about the token named ordi:
“tick”:”ordi”
“inscription_id”:
b61b0172d95e266c18aea0c624db987e971a5d6d4ebc2aaed85da4642d635735i0"
“supply”:”21000000"
“minted”:”21000000"
“limit_per_mint”:”1000"
“decimal”:18
“block_number”:779832
“creator”:”bc1pxaneaf3w4d27hl2y93fuft2xk6m4u3wc4rafevc6slgd7f5tq2dqyfgy06"
“timestamp”:”1678248991000"

2. Retrieve BRC-20 Balances series

  • Get BRC-20 owners by tick (retrieves a group of owners for a specific BRC-20 tick)
  • Get BRC-20 ticks by account (retrieves a group of wallet addresses for a specific BRC-20 tick)
  • Get a single BRC-20 tick by account (retrieves wallet address data for a single BRC-20 tick)

Here we retrieve details of owners holding the token with the name “ordi” using the Get BRC-20 owners by tick API at “/btc/brc20/balance/{tick}”, and a total of 12427 records are retrived.

3. MerlinProtocol BRC-20 Indexer series

  • Get ticker full history (retrieve complete historical records of a tick)
  • Get Address BRC-20 Summary (get a summary of BRC-20 tokens held by a specific address)
  • Get Transferable Inscriptions (retrieve transferable inscriptions for a BRC-20 token by address)
  • Get BRC-20 Holders (get BRC-20 token holders)

For example, by using the Get Address BRC-20 Summary interface for “/btc/brc20/address/{address}/brc20/summary”, you can retrieve all BRC-20 token summaries held by a specific address.

Building relevant NFT API requests

Developers can write code to call NFTScan API using different languages such as Python, Java, JavaScript, etc. For example, in Python, you can use the requests library to make API requests; in JavaScript, you can use axios; in Java, you can use OkHttp or Retrofit. When writing code, organize the interface parameters such as contract address, API Key, etc., call the corresponding NFTScan interface, and easily retrieve standardized JSON format data.

By utilizing interfaces Get Transferable Inscriptions: “/btc/brc20/address/{address}/brc20/{ticker}/transferable-inscriptions”, developers can access detailed data about transferable inscriptions of the ordi token held by the address:

bc1qggf48ykykz996uv5vsp5p9m9zwetzq9run6s64hm6uqfn33nhq0ql9t85q through an HTTP GET request to the NFTScan API. This request can be constructed using Python’s requests library.

import requests

def get_transferable_inscriptions(address, ticker, api_key):
"""
Call the NFTScan API to get detailed data of transferable BRC-20 tokens for a specific Bitcoin address.

Parameters:
address (str): Bitcoin address
ticker (str): BRC-20 token ticker
api_key (str): NFTScan API key

Returns:
dict: JSON data returned by the API
"""
# Define API base information
base_url = "https://api.nftscan.com/btc/brc20/address"
url = f"{base_url}/{address}/brc20/{ticker}/transferable-inscriptions"

# Set request headers
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}

# Send GET request
response = requests.get(url, headers=headers)

# Handle response
if response.status_code == 200:
# Request successful
return response.json()
else:
# Request failed
raise Exception(f"Error {response.status_code}: {response.text}")

if __name__ == "__main__":
# Define the Bitcoin address and BRC-20 token ticker to query
address = "bc1qggf48ykykz996uv5vsp5p9m9zwetzq9run6s64hm6uqfn33nhq0ql9t85q"
ticker = "ordi"
api_key = "YOUR_API_KEY" # Replace with your actual API key

try:
# Get transferable inscriptions data
data = get_transferable_inscriptions(address, ticker, api_key)
print("Transferable Inscriptions Data:", data)
except Exception as e:
print(e)Code Analysis

Function definition:

get_transferable_inscriptions: a function that takes parameters address, ticker, and api_key, used to call the NFTScan API and return JSON data.

Main program:

1/ Uses the if name == “main”: structure to ensure the script can be run directly.

2/ Defines the Bitcoin address, BRC-20 token ticker, and API key to be queried.

3/ Calls the get_transferable_inscriptions function and prints the returned JSON data.

4/ Uses try and except blocks to catch and handle potential exceptions.

Notes:

  • Replace “YOUR_API_KEY” with your actual NFTScan API key.
  • Make sure to have the requests library installed before running this script.

This script demonstrates how to call the NFTScan API to retrieve transferable detailed data of BRC-20 tokens for a specific address on the Bitcoin blockchain. If you are a developer in the NFT and Web3 space, feel free to utilize the NFTScan developer platform’s Bitcoin network NFT API data services to build products and protocols on the Bitcoin network quickly!

NFTScan is the world’s largest NFT data infrastructure, including a professional NFT explorer and NFT developer platform, supporting the complete amount of NFT data for 20+ blockchains including Ethereum, Solana, BNBChain, Arbitrum, Optimism, and other major networks, providing NFT API for developers on various blockchains.

Official Links:

NFTScan: https://nftscan.com

Developer: https://developer.nftscan.com

Twitter: https://twitter.com/nftscan_com

Discord: https://discord.gg/nftscan

Join the NFTScan Connect Program

--

--