sbtc

Build and manage sBTC deposits and withdrawals on Bitcoin and Stacks.

The sbtc package provides functions for creating sBTC deposits on Bitcoin and interacting with the sBTC protocol across Bitcoin and Stacks networks.

Installation

npm install sbtc

Deposit functions

buildSbtcDepositAddress

buildSbtcDepositAddress creates a Bitcoin address for sBTC deposits with embedded metadata.

Signature

function buildSbtcDepositAddress(options: DepositAddressOptions): DepositAddress

Parameters

Name
Type
Required
Description

stacksAddress

string

Yes

Stacks address to receive sBTC

signersPublicKey

string

Yes

Aggregated public key of signers

maxSignerFee

number

No

Maximum fee for signers (default: 80,000 sats)

reclaimLockTime

number

No

Lock time for reclaim script (default: 6,000)

network

BitcoinNetwork

No

Bitcoin network to use (default: MAINNET)

Example

buildSbtcDepositTx

buildSbtcDepositTx creates a complete Bitcoin transaction for sBTC deposits.

Signature

Parameters

Name
Type
Required
Description

amountSats

number | bigint

Yes

Amount to deposit in satoshis

stacksAddress

string

Yes

Stacks address to receive sBTC

signersPublicKey

string

Yes

Aggregated public key of signers

maxSignerFee

number

No

Maximum fee for signers (default: 80,000 sats)

reclaimLockTime

number

No

Lock time for reclaim (default: 144)

network

BitcoinNetwork

No

Bitcoin network to use

Example

sbtcDepositHelper

sbtcDepositHelper creates a fully-formed deposit transaction from UTXOs.

Signature

Parameters

Name
Type
Required
Description

amountSats

number | bigint

Yes

Amount to deposit in satoshis

stacksAddress

string

Yes

Stacks address to receive sBTC

signersPublicKey

string

Yes

Aggregated public key of signers

feeRate

number

Yes

Fee rate in sat/vbyte

utxos

UtxoWithTx[]

Yes

UTXOs to fund the transaction

bitcoinChangeAddress

string

Yes

Address for change output

reclaimPublicKey

string

No

Public key for reclaiming deposits

reclaimLockTime

number

No

Lock time for reclaim (default: 144)

maxSignerFee

number

No

Maximum signer fee (default: 80,000)

network

BitcoinNetwork

No

Bitcoin network (default: MAINNET)

Example

API clients

SbtcApiClientMainnet

SbtcApiClientMainnet provides mainnet API access for sBTC operations.

SbtcApiClientTestnet

SbtcApiClientTestnet provides testnet API access for sBTC operations.

SbtcApiClientDevenv

SbtcApiClientDevenv provides local development API access.

Client methods

fetchSignersPublicKey

fetchSignersPublicKey retrieves the aggregated public key of sBTC signers.

fetchSignersAddress

fetchSignersAddress retrieves the Bitcoin address of sBTC signers.

fetchFeeRate

fetchFeeRate retrieves current Bitcoin network fee rates.

fetchUtxos

fetchUtxos retrieves unspent transaction outputs for a Bitcoin address.

broadcastTx

broadcastTx broadcasts a Bitcoin transaction to the network.

notifySbtc

notifySbtc notifies the sBTC API about a deposit transaction.

fetchSbtcBalance

fetchSbtcBalance retrieves the sBTC balance for a Stacks address.

Configuration

Client configuration options

Name
Type
Description

sbtcContract

string

sBTC contract address

sbtcApiUrl

string

sBTC API (Emily) base URL

btcApiUrl

string

Bitcoin API base URL

stxApiUrl

string

Stacks API base URL

Custom client configuration

Complete deposit example

Was this helpful?