Skip to Content
HooksuseSbtcDeposit

useSbtcDeposit

Deposit BTC → sBTC. Builds the deposit with the official sbtc package, signs the PSBT (via the connect adapter or your override), broadcasts the Bitcoin transaction, notifies Emily, then polls deposit status in the background with backoff.

import { useSbtcDeposit } from '@baoku26/sbtc-sdk'; const { deposit, status, txid, depositAddress, error, reset } = useSbtcDeposit(config);

Signature

function useSbtcDeposit(config: UseSbtcDepositConfig): UseSbtcDepositResult;

Config

FieldTypeDescription
stacksAddressstringRecipient Stacks address that receives the minted sBTC.
bitcoinAddressstringBitcoin address funding the deposit and receiving change.
paymentPublicKeystringCompressed public key (hex) controlling the funding UTXOs.
reclaimPublicKey?stringKey allowed to reclaim an unprocessed deposit. Defaults to paymentPublicKey.
feeRate?'low' | 'medium' | 'high'Bitcoin fee tier. Default 'medium'.
maxSignerFee?numberCap (sats) on the fee the sBTC signers may take.
signPsbt?(psbt: Uint8Array) => Promise<Uint8Array>Override the signer. Defaults to adapter.connect.signPsbt.
pollIntervalMs?numberEmily poll interval while pending. Default 15000.
onSuccess?(bitcoinTxid: string) => voidCalled when the deposit confirms.
onError?(error: SbtcError) => voidCalled on failure.

When using a local self-custodial wallet, populate stacksAddress / bitcoinAddress / paymentPublicKey from useStacksWallet (address, btcAddress, publicKey).

Returns

FieldTypeDescription
deposit(amountSats)(number | bigint) => Promise<void>Build → sign → broadcast → notify Emily, then poll.
statusDepositStatusidle | building | signing | broadcasting | pending | confirmed | failed.
txidstring | nullBitcoin txid, once broadcast.
depositAddressstring | nullThe P2TR deposit address the BTC was sent to.
errorSbtcError | nullFailure detail (see below).
reset()() => voidReturn to idle and stop polling.

Example

import { useStacksWallet, useSbtcDeposit, DepositStatus } from '@baoku26/sbtc-sdk'; function Deposit() { const { address, btcAddress, publicKey } = useStacksWallet(); const { deposit, status, txid, error } = useSbtcDeposit({ stacksAddress: address!, bitcoinAddress: btcAddress!, paymentPublicKey: publicKey!, onSuccess: (btcTxid) => console.log('confirmed', btcTxid), }); return ( <> <button disabled={status !== DepositStatus.IDLE} onClick={() => deposit(100_000)}> Deposit 100k sats </button> <p>Status: {status}</p> {txid && <p>BTC txid: {txid}</p>} {error && <p>{error.code}: {error.message}</p>} </> ); }

Notes & errors

  • Amounts below the 546-sat dust minimum fail fast with DEPOSIT_BELOW_DUST.
  • Signing failures surface as PSBT_SIGNING_FAILED; pipeline/Emily failures as EMILY_API_ERROR (the message carries the underlying cause).
  • A transient polling blip is not a failure — the hook backs off and retries while pending.
  • The default signer deep-links to an external wallet (Leather / Xverse). To sign with a local key, pass a signPsbt override.
Last updated on