Skip to content

Decentral-America/data-service-client-js

DecentralChain

@decentralchain/data-service-client-js

Data service client for the DecentralChain blockchain.

npm license bundle size node


Overview

A TypeScript client library for interacting with the DecentralChain data service API. Provides typed methods for querying assets, pairs, candles, aliases, and transactions with built-in pagination, request batching, and input validation.

Part of the DecentralChain SDK.

Installation

npm install @decentralchain/data-service-client-js

Requires Node.js >= 24 and an ESM environment ("type": "module").

Quick Start

import { DataServiceClient } from '@decentralchain/data-service-client-js';

const client = new DataServiceClient({
  rootUrl: 'https://api.decentralchain.io/v0',
});

// Fetch assets
const { data: assets } = await client.getAssets(
  '4CYRBpSmNKqmw1PoKFoZADv5FaciyJcusqrHyPrAQ4Ca',
  'AENTt5heWujAzcw7PmGXi1ekRc7CAmNm87Q1xZMYXGLa',
);

// Fetch candles
const { data: candles } = await client.getCandles('AMOUNT_ASSET_ID', 'PRICE_ASSET_ID', {
  timeStart: '2024-01-01',
  timeEnd: '2024-12-31',
  interval: '1d',
  matcher: 'MATCHER_ADDRESS',
});

// Fetch exchange transactions with pagination
const result = await client.getExchangeTxs({ limit: 10, sort: 'desc' });
console.log(result.data);
if (result.fetchMore) {
  const next = await result.fetchMore(10);
  console.log(next.data);
}

API Reference

new DataServiceClient(options)

Creates a new client instance.

Option Type Required Description
rootUrl string Yes Base URL of the data service API
fetch Function No Custom fetch implementation
parse Function No Custom JSON parser
transform Function No Custom response transformer

Methods

Method Description
getAssets(...ids) Fetch assets by ID(s)
getAssetsByTicker(t) Fetch assets by ticker symbol
getCandles(a, p, opts) Fetch OHLCV candles for a pair
getPairs(matcher) Returns a function to fetch pairs
getExchangeTxs(opts?) Fetch exchange transactions
getTransferTxs(opts?) Fetch transfer transactions
getMassTransferTxs(opts?) Fetch mass transfer transactions
aliases.getById(id) Fetch alias by ID
aliases.getByIdList(ids) Fetch multiple aliases by IDs
aliases.getByAddress(addr, opts?) Fetch aliases by address

All methods return Promise<{ data: T; fetchMore?: (count: number) => Promise }>.

Assets

await client.getAssets('DCC'); // One asset
await client.getAssets('DCC', '8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS'); // Multiple
await client.getAssetsByTicker('DCC'); // By ticker
await client.getAssetsByTicker('*'); // All assets

Pairs

const getPairs = client.getPairs('MATCHER_ADDRESS');
await getPairs([assetPairA, assetPairB]);

Exchange Transactions

await client.getExchangeTxs('txId'); // By ID
await client.getExchangeTxs({ sender: '...', limit: 10, sort: 'desc' }); // With filters
await client.getExchangeTxs(); // Default (top 100)

Candles

await client.getCandles('DCC', '8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS', {
  timeStart: '2024-01-01',
  timeEnd: '2024-12-31',
  interval: '1d',
  matcher: 'MATCHER_ADDRESS',
});

Aliases

await client.aliases.getById('@myalias');
await client.aliases.getByIdList(['@alias1', '@alias2']);
await client.aliases.getByAddress('3P5uMgn1xvrm7g3sbUVAGLtetkNUa1AHn2M');

Pagination

const result = await client.getExchangeTxs({ limit: 1, sort: 'asc' });
if (result.fetchMore) {
  const next = await result.fetchMore(2);
}

Custom Options

const client = new DataServiceClient({
  rootUrl: 'https://api.decentralchain.io/v0',
  fetch: (url, options) => window.fetch(url, options).then((res) => res.text()),
  parse: (text) => JSON.parse(text),
  transform: ({ __type, data }) => data,
});

The pipeline is: fetchparsetransform

  • fetch must return a string
  • parse converts the string to a JavaScript object
  • transform processes the parsed response

Development

Prerequisites

  • Node.js >= 24 (LTS)
  • npm >= 10

Setup

git clone https://github.com/Decentral-America/data-service-client-js.git
cd data-service-client-js
npm install

Scripts

Command Description
npm run build Build distribution files (tsdown)
npm test Run tests with Vitest
npm run test:watch Tests in watch mode
npm run test:coverage Tests with V8 coverage
npm run typecheck TypeScript type checking
npm run lint Biome lint (type-aware)
npm run lint:fix Biome lint with auto-fix
npm run format Format with Biome
npm run validate Full CI validation pipeline
npm run bulletproof Format + lint fix + typecheck + test

Quality Gates

Pre-commit hooks run lefthook + typecheck automatically.

The validate pipeline checks:

  • Formatting (Biome)
  • Linting (Biome with strict rules)
  • Type checking (TypeScript strict mode)
  • Tests with coverage thresholds (90%+)
  • Build (tsdown ESM output)
  • Package validation (publint + attw)
  • Bundle size limits (size-limit)

Related packages

Package Description
@decentralchain/bignumber Arbitrary-precision arithmetic
@decentralchain/data-entities Asset, Money, and OrderPrice models
@decentralchain/ts-types Core TypeScript type definitions
@decentralchain/node-api-js Node REST API client

Contributing

See CONTRIBUTING.md.

Security

To report a vulnerability, see SECURITY.md.

License

MIT — Copyright (c) DecentralChain

About

HTTP client for the DecentralChain data service API — asset search, transaction history, DEX data

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors