BigBlocks

Sweep Wallet

Sweep assets from a WIF private key into the connected wallet with scan, preview, and progress

Installation

bunx shadcn@latest add https://registry.bigblocks.dev/r/sweep-wallet.json

Usage

SweepWallet provides a full WIF-input, scan, preview, and sweep flow. Supply onScan and onSweep callbacks wired to your wallet backend.

import { SweepWallet } from "@/components/blocks/sweep-wallet"
 
export function ImportWallet() {
  return (
    <SweepWallet
      onScan={async (wif) => {
        // Scan the WIF for spendable UTXOs, ordinals, and tokens
        const pk = PrivateKey.fromWif(wif)
        const address = pk.toPublicKey().toAddress()
        return await scanAddressUtxos(services, address)
      }}
      onSweep={async (wif, assets) => {
        // Sweep all found assets into the connected wallet
        const inputs = await prepareSweepInputs(ctx, assets.funding)
        return await sweepBsv.execute(ctx, { inputs, wif })
      }}
      onSuccess={(result) => console.log("Swept:", result.txid)}
      onError={(err) => console.error(err)}
    />
  )
}

Props

SweepWallet

PropTypeDefaultDescription
onScan(wif: string) => Promise<ScanResult>requiredScan a WIF for spendable assets
onSweep(wif: string, assets: ScanResult) => Promise<SweepResult>requiredExecute the sweep transaction
onSuccess(result: SweepResult) => void--Called after a successful sweep
onError(error: Error) => void--Called on error
classNamestring--Additional CSS classes

ScanResult

interface ScanResult {
  funding: SweepFundingUtxo[]
  ordinals: SweepOrdinalUtxo[]
  tokens: SweepTokenGroup[]
  totalSats: number
}

SweepResult

interface SweepResult {
  txid?: string
  error?: string
}