bitflow-sdk
TypeScript icon, indicating that this package has built-in type declarations

1.6.1 • Public • Published

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.

Table of Contents

  1. Installation
  2. Configuration
  3. Usage
  4. Troubleshooting
  5. License

Installation

Install the Bitflow SDK using npm:

npm install bitflow-sdk

Configuration

Before using the Bitflow SDK, you need to set up your environment variables. Create a .env file in your project root with the following variables:

API_HOST=your_api_host_here (will be provided by Bitflow)

API_KEY=your_api_key_here (will be provided by Bitflow)

STACKS_API_HOST="https://api.hiro.so"

READONLY_CALL_API_HOST=your_readonly_call_api_host_here (will be provided by Bitflow)

Usage

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

  1. Import the SDK:
import { BitflowSDK } from 'bitflow-sdk';
  1. Initialize the SDK:
const bitflow = new BitflowSDK();
  1. Use the SDK methods to interact with the Bitflow Protocol. Here are some common operations:

Available Functions

1. Get Available Tokens

Retrieve a list of all available tokens:

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

2. Get Possible Swaps

Get all possible swap options for a given token:

const tokenX = 'STX';
const swapOptions = await bitflow.getPossibleSwaps(tokenX);
console.log(swapOptions);

3. Get All Possible Token Y

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

const tokenX = 'STX';
const possibleTokens = await bitflow.getAllPossibleTokenY(tokenX);
console.log(possibleTokens);

4. Get All Possible Token Y Routes

Get the quotes for a swap between two tokens:

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

6. Execute Swap

Execute a swap transaction:

const tokenX = 'token-stx';
const tokenY = 'token-usda';
const amount = 100;
const senderAddress = 'SP...'; // Your Stacks address
const slippageTolerance = 0.01; // 1% slippage tolerance

const quoteResult = await bitflow.getQuoteForRoute(tokenX, tokenY, amount);
if (quoteResult.bestRoute) {
  await bitflow.executeSwap(
    {
      route: quoteResult.bestRoute.route,
      amount: amount
    },
    senderAddress,
    slippageTolerance
  );
}

Troubleshooting

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

  1. Ensure all environment variables are correctly set in your .env file.
  2. Make sure you have the latest version of the SDK installed.
  3. Check that you're using a valid Stacks address for the senderAddress parameter.

License

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

Package Sidebar

Install

npm i bitflow-sdk

Weekly Downloads

129

Version

1.6.1

License

MIT

Unpacked Size

184 kB

Total Files

84

Last publish

Collaborators

  • setpato