npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@faktoryfun/styx-sdk

v1.3.5

Published

Bitcoin deposit SDK for Stacks applications, enabling trustless Bitcoin-to-sBTC deposits

Readme

@faktoryfun/styx-sdk

A Bitcoin deposit SDK for Stacks applications, enabling trustless Bitcoin-to-sBTC deposits.

Installation

npm install @faktoryfun/styx-sdk
# or
yarn add @faktoryfun/styx-sdk

For a complete working example of an application integrating this SDK, check out the Styx Integration Example repository.

Features

  • Manage Bitcoin deposits to sBTC
  • Handle UTXOs and transaction preparation
  • Support for popular Stacks/Bitcoin wallets (Leather, Xverse)
  • Fee estimation and management
  • Transaction execution and status tracking
  • Protection against inscriptions in UTXOs
  • Pool status monitoring
  • BTC price fetching

Usage

Basic Setup

import { styxSDK, TransactionPriority } from "@faktoryfun/styx-sdk";

// The default export uses pre-configured credentials
// You can also create a customized instance:
const customSDK = new StyxSDK("https://your-api-url.com", "your-api-key");

Preparing a Transaction

const prepareTransaction = async () => {
  try {
    const transactionData = await styxSDK.prepareTransaction({
      amount: "0.001", // BTC amount as string
      userAddress: "SP...", // STX address
      btcAddress: "bc1...", // BTC address
      feePriority: TransactionPriority.Medium,
      walletProvider: "leather", // "leather" or "xverse"
    });

    console.log("Transaction prepared:", transactionData);
    return transactionData;
  } catch (error) {
    console.error("Error preparing transaction:", error);
  }
};

Creating a Deposit

const createDeposit = async () => {
  try {
    const depositId = await styxSDK.createDeposit({
      btcAmount: 0.001, // BTC amount as number
      stxReceiver: "SP...", // STX address
      btcSender: "bc1...", // BTC address
    });

    console.log("Deposit created with ID:", depositId);
    return depositId;
  } catch (error) {
    console.error("Error creating deposit:", error);
  }
};

Executing a Transaction

const executeTransaction = async (depositId, preparedData) => {
  try {
    const result = await styxSDK.executeTransaction({
      depositId,
      preparedData,
      walletProvider: "leather", // "leather" or "xverse"
      btcAddress: "bc1...", // BTC address
    });

    console.log("Transaction executed:", result);
    return result;
  } catch (error) {
    console.error("Error executing transaction:", error);
  }
};

Updating Deposit Status

const updateDepositStatus = async (depositId, txId) => {
  try {
    const result = await styxSDK.updateDepositStatus({
      id: depositId,
      data: {
        btcTxId: txId,
        status: "broadcast",
      },
    });

    console.log("Deposit status updated:", result);
    return result;
  } catch (error) {
    console.error("Error updating deposit status:", error);
  }
};

Transaction Status Tracking

The Styx SDK now provides flexible methods to monitor deposit status throughout the transaction lifecycle. Use getDepositStatus(depositId) to look up deposits by their unique identifier or getDepositStatusByTxId(btcTxId) to query using the Bitcoin transaction hash. The latter is especially valuable for wallet integrations, allowing users to recover deposit information even if they've lost track of the deposit ID. Implementation is straightforward:

// Check status using deposit ID
const depositStatus = await styxSDK.getDepositStatus("123");

// Check status using Bitcoin transaction ID after broadcast
const sameDepositStatus = await styxSDK.getDepositStatusByTxId(
  "2f9ad639e10d0609431a5c1c5b0b5a0f369c14a46f5f3452ababc85c7b2be7d3"
);

console.log("Current status:", depositStatus.status); // "broadcast", "processing", "confirmed", etc.

Getting Deposit History

const getHistory = async (userAddress) => {
  const history = await styxSDK.getDepositHistory(userAddress);
  console.log("Deposit history:", history);
  return history;
};

Getting All Deposits History

const getAllDepositsHistory = async () => {
  const allDeposits = await styxSDK.getAllDepositsHistory();
  console.log("All deposits:", allDeposits);
  return allDeposits;
};

Getting Fee Estimates

const getFees = async () => {
  const fees = await styxSDK.getFeeEstimates();
  console.log("Current fee estimates (sats/vB):", fees);
  return fees;
};

Getting Pool Status

const getPoolStatus = async () => {
  const status = await styxSDK.getPoolStatus();
  console.log("Pool status:", status);
  /*
    {
      realAvailable: 0.5,      // BTC
      estimatedAvailable: 0.45, // BTC (accounting for pending deposits)
      lastUpdated: 1687245600000 // timestamp
    }
  */
  return status;
};

Getting BTC Price

const getBTCPrice = async () => {
  const price = await styxSDK.getBTCPrice();
  console.log("Current BTC price (USD):", price);
  return price;
};

Deposit Limitations

  • Minimum deposit: 10,000 sats (0.0001 BTC)
  • Maximum deposit: 400,000 sats (0.004 BTC)

Status Management

The SDK handles different deposit statuses which are crucial for properly managing sBTC liquidity in the pool:

  • initiated - Initial deposit record created
  • broadcast - Bitcoin transaction has been broadcast to the network
  • processing - Transaction is being processed (has at least 1 confirmation)
  • confirmed - Transaction is confirmed (has required number of confirmations)
  • refund-requested - User has requested a refund
  • canceled - Deposit was canceled and liquidity released back to the pool

Important: Always update the deposit status after a transaction is broadcast or canceled to ensure accurate pool liquidity accounting.

API Reference

StyxSDK Class

| Method | Parameters | Return Type | Description | | ------------------------ | ----------------------------------------------------- | ------------------------------------- | ---------------------------------------------------- | | getFeeEstimates | None | Promise<FeeEstimates> | Get current Bitcoin network fee estimates | | createDeposit | DepositCreateParams | Promise<string> | Create a new deposit record and get its ID | | updateDeposit | DepositUpdateParams | Promise<any> | Update an existing deposit record | | updateDepositStatus | id, data | Promise<any> | Update the status of an existing deposit | | getDepositStatus | depositId | Promise<Deposit> | Get status of a deposit by its ID | | getDepositStatusByTxId | btcTxId | Promise<Deposit> | Get status of a deposit by Bitcoin transaction ID | | getDepositHistory | userAddress | Promise<Deposit[]> | Get deposit history for a specific user | | getAllDepositsHistory | None | Promise<Deposit[]> | Get all deposits (admin function) | | prepareTransaction | TransactionPrepareParams | Promise<PreparedTransactionData> | Prepare a transaction with UTXOs and fee calculation | | executeTransaction | depositId, preparedData, walletProvider, btcAddress | Promise<ExecuteTransactionResponse> | Execute a prepared transaction | | getPoolStatus | None | Promise<PoolStatus> | Get current pool status and available liquidity | | getBTCPrice | None | Promise<number \| null> | Get current BTC price in USD |

Types

// Important types used in the SDK
export type TransactionPriority = "low" | "medium" | "high";

export interface DepositCreateParams {
  btcAmount: number;
  stxReceiver: string;
  btcSender: string;
}

export interface PreparedTransactionData {
  utxos: Array<any>;
  opReturnData: string;
  depositAddress: string;
  fee: number;
  changeAmount: number;
  amountInSatoshis: number;
  feeRate: number;
  inputCount: number;
  outputCount: number;
  inscriptionCount: number;
}

export interface PoolStatus {
  realAvailable: number;
  estimatedAvailable: number;
  lastUpdated: number;
}

export interface FeeEstimates {
  low: number;
  medium: number;
  high: number;
}

Constants

The SDK provides useful constants for minimum and maximum deposit amounts:

import { MIN_DEPOSIT_SATS, MAX_DEPOSIT_SATS } from "@faktoryfun/styx-sdk";

console.log("Minimum deposit (sats):", MIN_DEPOSIT_SATS); // 10000 sats (0.0001 BTC)
console.log("Maximum deposit (sats):", MAX_DEPOSIT_SATS); // 400000 sats (0.004 BTC)

License

MIT