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.
Install the Bitflow SDK using npm:
npm install bitflow-sdk
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)
Here's a step-by-step guide to implement the Bitflow SDK in your project:
- Import the SDK:
import { BitflowSDK } from 'bitflow-sdk';
- Initialize the SDK:
const bitflow = new BitflowSDK();
- Use the SDK methods to interact with the Bitflow Protocol. Here are some common operations:
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
);
}
If you encounter any issues while using the Bitflow SDK, please check the following:
- Ensure all environment variables are correctly set in your .env file.
- Make sure you have the latest version of the SDK installed.
- Check that you're using a valid Stacks address for the senderAddress parameter.
This project is licensed under the MIT License - see the LICENSE file for details.