Bitcoin Stamps StampsClass SDK Documentation
This SDK provides functions to interact with the StampChain API for managing and retrieving Bitcoin Stamps data. It supports fetching stamps by various criteria such as total count, page, block index, subprotocol, and specific identifiers. Please refer to https://stampchain.io/docs for more information on the StampChain API.
import { PROTOCOL_IDENTIFIERS as SUBPROTOCOLS } from "utils/protocol.ts";
RESPONSE_LIMIT
: The default limit per page for fetching stampsSTAMPCHAIN_API_URL
: The base URL for the StampChain API (https://stampchain.io/api/v2
).
Fetches the total count of stamps and the last block index from the API.
Promise<{ total: number, lastBlock: number }>
: An object containing the total count of stamps and the last block index.
const { total, lastBlock } = await StampsClass.fetch_count_of_total_stamps();
Fetches a specific page of stamps from the API. Can be used with pagination.
limit
: The number of stamps to fetch per page. Defaults toRESPONSE_LIMIT
.page
: The page number to fetch. Defaults to 1.sort_order
: The order in which to sort the stamps. Can be 'asc' or 'desc'. Defaults to 'asc'.
Promise<Object>
: An object containing the fetched page of stamps.
const stampsPage = await StampsClass.fetch_stamps_by_page(100, 2, "desc");
Fetches stamps by block index from the API.
block_index
: The block index for which to fetch the stamps.
Promise<Object>
: The data returned by the API. This includes information about the last block, the block info, and an array of data for each stamp in the block.
const stampsData = await StampsClass.fetch_stamps_by_block_index(830000);
Fetches stamps by subprotocol from the API.
ident
: The subprotocol for which to fetch the stamps. This should be one of the values defined in theSUBPROTOCOLS
object.limit
: The maximum number of stamps to fetch. Defaults to 100.page
: The page number to fetch. Defaults to 1.
Promise<Object>
: The data returned by the API. This includes information about the page, limit, total pages, total stamps, last block, ident, and an array of data for each stamp.
const stampsData = await StampsClass.fetch_stamps_by_subprotocol(
SUBPROTOCOLS.STAMP,
100,
1,
);
Fetches a single stamp by its identifier from the API.
identifier
: The identifier for which to fetch the stamp. This should be one of [tx_hash, stamp, cpid, or stamp_hash].
Promise<Object>
: The data returned by the API. This includes information about the last block and the stamp data.
const stampData = await StampsClass.fetch_stamp_by_identifier("23");