Bitflow SDK
An overview of the Bitflow SDK, including installation, configuration, and usage in your project.
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. Currently, the SDK is available by request only. If you are interested in integrating with the BitFlow SDK please reach out to the team on Discord.
Table of Contents
Bitflow SDK
Table of Contents
Installation
Configuration
Usage
Available Functions
Get Available Tokens
Get Possible Swaps
Get All Possible Token Y
Get All Possible Token Y Routes
Getting Quote for Route
Getting Swap Parameters
Executing Swap (uses
@stacks/connect
)
Bitflow SDK - Keeper Functions
Get or Create Keeper Contract
Create Order
Get Order
Get User
Get Quote
Create Group Order
Get Group Order
Cancel Order
Cancel Group Order
Get Keeper Tokens
Get Keeper Possible Swaps
Get All Keeper Possible Token Y
Get All Keeper Possible Token Y Routes
Get Keeper Quote For Route
Example of BTC to sBTC
Types
Outline of Optional Parameters
Troubleshooting
License
Installation
Install the Bitflow SDK using npm:
Latest Stable Version is 1.6.1
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:
Usage
Here's a step-by-step guide to implement the Bitflow SDK in your project:
Import the SDK:
Initialize the SDK:
Use the SDK methods to interact with the Bitflow Protocol. Here are some common operations:
Available Functions
Get Available Tokens
Retrieve a list of all available tokens:
Get Possible Swaps
Get all possible swap options for a given token:
Get All Possible Token Y
Retrieve all possible tokens that can be swapped for a given token:
Get All Possible Token Y Routes
Get all possible routes for swapping between two tokens:
Getting Quote for Route
Get the quotes for a swap between two tokens:
Getting Swap Parameters
Get the necessary parameters for signing a swap transaction:
Executing Swap (uses @stacks/connect
)
@stacks/connect
)This function uses the @stacks/connect
library to execute a swap transaction:
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.
Bitflow SDK - Keeper Functions
The Bitflow SDK also provides a set of Keeper functions that enable automated token swaps and order management on the Stacks blockchain. These functions allow your application to interact with the Keeper service for executing various types of token operations.
Available Keeper Functions
Get or Create Keeper Contract
Get an existing keeper contract or create a new one for a Stacks address:
Create Order
Create a new swap or action order:
Get Order
Retrieve details of a specific order by its ID:
Get User
Get user information including their associated Keeper contracts and orders:
Get Quote
Get a price quote for a Keeper action:
Create Group Order
Create a group of orders to be executed according to a schedule:
Get Group Order
Retrieve details of a specific group order:
Cancel Order
Cancel a specific order:
Cancel Group Order
Cancel a group order:
Get Keeper Tokens
Get tokens that are compatible with the Keeper service:
Get Keeper Possible Swaps
Get all possible swap options for a given token using the Keeper service:
Get All Keeper Possible Token Y
Retrieve all possible tokens that can be swapped for a given token using the Keeper service:
Get All Keeper Possible Token Y Routes
Get all possible Keeper routes for swapping between two tokens:
Get Keeper Quote For Route
Get the quotes for a swap between two tokens using the Keeper service:
Example of BTC to sBTC
Call the Pontis SDKβs createSendBTC function as follows. This function takes the scaled BTC amount, fee information, and the keeperβs (recipient) address, and it uses a callback (that internally calls doSignAndBroadcastPsbt) to sign and broadcast the transaction. Once broadcast, it returns a claim (the transaction id):
After you have the txId (claim) from createSendBTC, you create the onβchain order to bridge BTC to sBTC. Use the claim as the bitcoinTxId in your order parameters. For example:
Outline of Optional Parameters
If a parameter is listed in this list, we consider it as an optional parameter needed to be passed along for the specified endpoint. createGroupOrder
:
bitcoinTxId
orstacksTxId
optinal, can be provided for most actions -- depending on theactionType
, no transaction needs to be provided (but providing one is still recommended)fundingTokens
: optional, should be used for most actionsminReceived
: optional, should be used in most casesbitcoinAddress
: optionalactionFunctionArgs
,actionPostConditions
, andactionAggregatorTokens
: optional --actionAggregatorTokens
is used for almost all swap-related actions.actionFunctionArgs
andactionPostConditions
are mostly used for actions such as adding liquiditynextExecutionAfter
: optionalpriceRange
: optionalfeeRecipient
: optional
createOrder
:
Same as above, but includes
cancelOrderAfter
, which is optional
getGroupOrder
:
includeOrders
: optional
getOrCreateKeeperContract
: Depending on the keeperType
, bitcoinAddress
is optional but providing it is still recommended
deployContract
: optionalallActionsApproved
: optional
Troubleshooting
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.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Last updated