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 🙏

© 2024 – Pkg Stats / Ryan Hefner

sbtc

v0.1.9

Published

Library for sBTC.

Downloads

87

Readme

sbtc 0.1.x (developer-release)

A helper package for interacting with sBTC from JavaScript/TypeScript.

Installation

npm install sbtc

Basic Usage

The package exports two high-level helpers for interacting with sBTC:

  • sbtcDepositHelper — create a deposit transaction (assuming spendable bitcoin UTXOs, and the sBTC peg address)
  • sbtcWithdrawHelper — create a withdraw transaction (assuming spendable UTXOs, sBTC balance, a Stacks sBTC-withdraw signature via sbtcWithdrawMessage, and the sBTC peg address)

Additionally, there are two API helpers, which make it easier to get all the data needed to create the above transactions:

  • DevEnvHelper — a helper for interacting with a local development environment sbtc/devenv
  • TestnetHelper — a helper for interacting with the testnet deployment of the sBTC contract

Examples

sbtcDepositHelper

import { DevEnvHelper, sbtcDepositHelper } from 'sbtc';

const dev = new DevEnvHelper();

// Transaction building
const tx = await sbtcDepositHelper({
  pegAddress: await dev.getSbtcPegAddress(),

  stacksAddress: MY_STX_ADDRESS,
  amountSats: 1_000, // amount of BTC to deposit, in satoshis

  feeRate: await dev.estimateFeeRate('low'),
  utxos: await dev.fetchUtxos(MY_BTC_ADDRESS);

  bitcoinChangeAddress: MY_BTC_ADDRESS,
});

// Transaction signing and broadcasting
tx.sign(MY_BTC_PRIVATE_KEY);
tx.finalize();

const txid = await dev.broadcastTx(tx);
console.log('txid', txid)

// Or: export as PSBT for signing with a different wallet
const psbtBytes = tx.toPSBT();

Note: Here DevEnvHelper can be replaced with TestnetHelper to interact with the testnet deployment of the sBTC contract.

sbtcWithdrawHelper

import { DevEnvHelper, sbtcWithdrawHelper, sbtcWithdrawMessage } from 'sbtc';

const dev = new DevEnvHelper();

const message = sbtcWithdrawMessage({
  amountSats: 1_000,
  bitcoinAddress: MY_BTC_ADDRESS, // withdrawl recipient
});

const signature = signMessageHashRsv({
  messageHash: bytesToHex(hashMessage(message)),
  privateKey: createStacksPrivateKey(MY_STX_PRIVATE_KEY),
}).data; // Or: sign message with a different wallet

// Tx building
const tx = await sbtcWithdrawHelper({
  pegAddress: await dev.getSbtcPegAddress(),

  amountSats: 1_000, // amount of BTC to withdraw, in satoshis
  bitcoinAddress: MY_BTC_ADDRESS, // withdrawl recipient
  signature,

  fulfillmentFeeSats: 2_000,

  feeRate: await dev.estimateFeeRate('low'),
  utxos: await dev.fetchUtxos(MY_BTC_ADDRESS),

  bitcoinChangeAddress: MY_BTC_ADDRESS,
});

// Transaction signing and broadcasting
tx.sign(MY_BTC_PRIVATE_KEY);
tx.finalize();

const txid = await dev.broadcastTx(tx);
console.log('txid', txid);

// Or: export as PSBT for signing with a different wallet
const psbtBytes = tx.toPSBT();

Note: Here DevEnvHelper can be replaced with TestnetHelper to interact with the testnet deployment of the sBTC contract.

DevEnvHelper / TestnetHelper

import { DevEnvHelper, TestnetHelper } from 'sbtc';

// const test = new TestnetHelper(); // interchangeable
const dev = new DevEnvHelper();

await dev.getBitcoinAccount('secure glass …'); // The Bitcoin account for a given seed phrase
await dev.getStacksAccount('secure glass …'); // The Stacks account for a given seed phrase

await dev.getSbtcPegAddress(); // The sBTC peg address

await dev.estimateFeeRate('low'); // The estimated fee rate
await dev.fetchUtxos(MY_BTC_ADDRESS); // The spendable BTC UTXOs for a given address
await dev.fetchTxHex(TXID); // The raw BTC transaction for a given txid
await dev.broadcastTx(TX); // Broadcast a BTC transaction

await dev.getBalance(BTC_ADDRESS);
await dev.getSbtcBalance(STX_ADDRESS);

await dev.stacksCallReadOnly({
  contractAddress: '…',
  functionName: '…',
});