@bitflowlabs/core-sdk

中文文档
4.2.0发布于 2026/08/20MITTypeScriptCommonJS近 30 天下载 4880

SDK for interacting with Bitflow Protocol

原始使用文档
文档目录8 节
  1. Environment Variables
  2. Get Available Tokens
  3. Get Possible Swaps
  4. Get All Possible Token Y
  5. Get All Possible Token Y Routes
  6. Getting Quote for Route
  7. Getting Swap Parameters
  8. Executing Swap (uses @stacks/connect )

Bitflow SDK

Bitflow SDK is a powerful and easy-to-use library for interacting with the Bitflow Protocol. It provides a set of tools to seamlessly integrate Bitflow functionality into your applications.

All Bitflow API endpoints are publicly accessible without an API key. Unauthenticated requests are subject to a default rate limit of 500 requests per minute per IP.

If your integration requires higher limits, see the Rate Limit Request section to email [email protected] with a pre-filled form. You can also reach the team on Discord.

Table of Contents

Installation

Install the Bitflow SDK using npm:

npm install @bitflowlabs/core-sdk

Usage

Here's a step-by-step guide to implement the Bitflow SDK in your project:

  1. Import the SDK:
import { BitflowSDK } from '@bitflowlabs/core-sdk';
  1. Initialize the SDK:

The SDK can be instantiated with no arguments. Built-in defaults are used for all host URLs, so only provide overrides when necessary. See the Environment Variables section for all available options.

// Zero-config — uses built-in defaults for all host URLs.
const bitflow = new BitflowSDK();

// Override individual values as needed.
const bitflow = new BitflowSDK({
  BITFLOW_PROVIDER_ADDRESS: string, // optional
  BITFLOW_API_KEY: string, // optional
  BITFLOW_API_HOST: string,     // optional, default: https://bitflowsdk-api-test-7owjsmt8.uk.gateway.dev
  READONLY_CALL_API_HOST: string, // optional, default: https://node.bitflowapis.finance
  READONLY_CALL_API_KEY: string, // optional
  KEEPER_API_HOST: string,      // optional, default: https://bitflow-keeper-test-7owjsmt8.uc.gateway.dev
  KEEPER_API_KEY: string, // optional
});
  1. Use the SDK methods to interact with the Bitflow Protocol. See the Available Functions section for more details.

Environment Variables

All configuration has built-in defaults — no environment variables are required to get started.

When an environment variable is set it takes precedence over the built-in default. Constructor options passed directly to new BitflowSDK({ ... }) take the highest precedence.

VariableDefault
BITFLOW_API_HOSThttps://bitflowsdk-api-test-7owjsmt8.uk.gateway.dev
READONLY_CALL_API_HOSThttps://node.bitflowapis.finance
KEEPER_API_HOSThttps://bitflow-keeper-test-7owjsmt8.uc.gateway.dev
BITFLOW_API_KEY(none — public rate limits apply)
READONLY_CALL_API_KEY(none — public rate limits apply)
KEEPER_API_KEY(none — public rate limits apply)
BITFLOW_PROVIDER_ADDRESS(none)

To override via environment variables, create a .env file in your project root:

# Override host URLs only if you need to point at a different environment
BITFLOW_API_HOST=https://bitflowsdk-api-test-7owjsmt8.uk.gateway.dev
READONLY_CALL_API_HOST=https://node.bitflowapis.finance
KEEPER_API_HOST=https://bitflow-keeper-test-7owjsmt8.uc.gateway.dev

# Optional: API keys for higher rate limits (see Rate Limit Request section below)
BITFLOW_API_KEY=<your_api_key_here>
READONLY_CALL_API_KEY=<your_readonly_api_key_here>
KEEPER_API_KEY=<your_keeper_api_key_here>

# Optional: your Stacks provider address
BITFLOW_PROVIDER_ADDRESS=<your_provider_address_here>

Next.js NEXT_PUBLIC_ prefixed variants are also supported for all variables above (e.g. NEXT_PUBLIC_BITFLOW_API_HOST).

Available Functions

Get Available Tokens

Retrieve a list of all available tokens:

const tokens = await bitflow.getAvailableTokens();
console.log(tokens);

Get Possible Swaps

Get all possible swap options for a given token:

const tokenXId = 'token-stx'; // the `tokenId` prop from `Token` interface
const swapOptions = await bitflow.getPossibleSwaps(tokenXId);
console.log(swapOptions);

Get All Possible Token Y

Retrieve all possible tokens that can be swapped for a given token:

const tokenXId = 'token-stx';
const possibleTokens = await bitflow.getAllPossibleTokenY(tokenXId);
console.log(possibleTokens);

Get All Possible Token Y Routes

Get all possible routes for swapping between two tokens:

const tokenXId = 'token-usda';
const tokenYId = 'token-stx';
const routes = await bitflow.getAllPossibleTokenYRoutes(tokenXId, tokenYId);
console.log(routes);

Getting Quote for Route

Get the quotes for a swap between two tokens:

const tokenXId = 'token-usda';
const tokenYId = 'token-stx';
const amount = 100; // Amount of tokenX to swap
const quoteResult = await bitflow.getQuoteForRoute(tokenXId, tokenYId, amount);
console.log(quoteResult);

Getting Swap Parameters

Get the necessary parameters for signing a swap transaction:

const swapExecutionData = {
  route: selectedRoute,
  amount: 100,
  tokenXDecimals: selectedRoute.tokenXDecimals,
  tokenYDecimals: selectedRoute.tokenYDecimals,
};
const senderAddress = 'your_stacks_address';
const slippageTolerance = 0.01; // 1%

const swapParams = await bitflow.getSwapParams(
  swapExecutionData,
  senderAddress,
  slippageTolerance
);
console.log(swapParams); // Use this parameters to build your swap transaction

Executing Swap (uses @stacks/connect)

This function uses the @stacks/connect library to execute a swap transaction:

const swapExecutionData = {
  route: selectedRoute,
  amount: 100,
  tokenXDecimals: selectedRoute.tokenXDecimals,
  tokenYDecimals: selectedRoute.tokenYDecimals,
};
const senderAddress = 'your_stacks_address';
const slippageTolerance = 0.01; // 1%

await bitflow.executeSwap(
  swapExecutionData,
  senderAddress,
  slippageTolerance,
  stacksProvider, // a valid object of type `StacksProvider` from `@stacks/connect`
  (data) => console.log('Swap executed:', data),
  () => console.log('Swap cancelled')
);

Types

The SDK exports several TypeScript types that you can use in your application:

  • BitflowSDKConfig: Represents the configuration object for the Bitflow SDK.
  • Token: Represents a token with its properties.
  • SwapOptions: Represents possible swap options for a token.
  • PostConditionType: Represents the type of a post-condition used in transactions.
  • SelectedSwapRoute: Represents a selected swap route with its details.
  • RouteQuote: Represents the quote for a swap route.
  • QuoteResult: Represents the result of a quote request, including the best RouteQuote and all possible routes.
  • SwapExecutionData: Represents the data needed to execute a swap.
  • SwapDataParamsAndPostConditions: Represents the parameters and post-conditions needed to execute/sign a swap transaction.
import {
  Token,
  SwapOptions,
  SelectedSwapRoute,
  QuoteResult,
  SwapExecutionData,
  SwapDataParamsAndPostConditions,
} from '@bitflowlabs/core-sdk';

Troubleshooting

If you encounter any issues while using the Bitflow SDK, please check the following:

  1. Make sure you have the latest version of the SDK installed.
  2. Check that you're using a valid Stacks address for the senderAddress parameter.
  3. If you're overriding host URLs via environment variables, ensure they are correctly set in your .env file.

Rate Limit Request

If your integration needs more than 500 requests per minute per IP, click the link below to open a pre-filled email in your mail client:

Request higher rate limits

If the link doesn't open your mail client, email [email protected] with the subject API Rate Limit Increase Request and include the following:

  • Project / Application name — e.g. MyDeFi App
  • Brief description — What your app does and how it uses the Bitflow API
  • Website / repo (if public) — URL or N/A
  • APIs you need higher limits for — Core API, Keeper API, Stacks Node (or all)
  • Expected request volume — e.g. ~2,000 requests/minute during peak hours
  • Use case — e.g. Server-side data aggregation, real-time price feeds for N users
  • Contact name
  • Discord handle (optional)

We aim to respond within 2 business days. For urgent requests, reach out on Discord.

License

This project is licensed under the MIT License - see the LICENSE file for details.

版本与发布记录

@bitflowlabs/core-sdk 共发布 26 个版本,首次发布于 2024/10/05;过去 12 个月发布了 10 个版本。

版本发布日期距今
4.2.0latest2026/08/202 个月前
4.1.02026/07/303 个月前
4.0.02026/07/213 个月前
3.1.02026/04/037 个月前
3.0.02026/02/268 个月前
3.0.0-beta.0beta2026/02/268 个月前

关于 @bitflowlabs/core-sdk 的常见问题

@bitflowlabs/core-sdk 是什么?

SDK for interacting with Bitflow Protocol

如何安装 @bitflowlabs/core-sdk?

在项目目录运行 npm install @bitflowlabs/core-sdk,或使用 pnpm add / yarn add / bun add。

@bitflowlabs/core-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bitflowlabs/core-sdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@bitflowlabs/core-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bitflowlabs/core-sdk 可以商用吗?

@bitflowlabs/core-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bitflowlabs/core-sdk 的下载量有多少?

根据 npm 官方下载统计,@bitflowlabs/core-sdk 在 2026/10/08 – 2026/11/06 这 30 天内被下载 4,880 次,日均约 163 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bitflowlabs/core-sdk 还在维护吗?

最新版本 4.2.0 发布于 2026/08/20(2 个月前);至今共发布 26 个版本,其中过去 12 个月发布了 10 个;首次发布于 2024/10/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。