BigBlocks

Send BSV21

Token send form with selector dropdown, decimal-aware amount input, recipient address, and confirmation flow for BSV21 fungible tokens

Installation

bunx shadcn@latest add https://registry.bigblocks.dev/r/send-bsv21.json

Usage

SendBsv21 accepts an array of token balances and an onSend callback. The amount in SendBsv21Params is a raw integer string accounting for token decimals.

import { SendBsv21 } from "@/components/blocks/send-bsv21"
import { sendBsv21, createContext } from "@1sat/actions"
import { useWallet } from "@1sat/react"
 
export function TokenTransfer() {
  const { wallet } = useWallet()
  const ctx = createContext(wallet)
 
  return (
    <SendBsv21
      balances={tokenBalances}
      onSend={async ({ tokenId, amount, address }) => {
        const result = await sendBsv21.execute(ctx, { tokenId, amount, address })
        return result
      }}
      onSuccess={(result) => console.log("txid:", result.txid)}
      onError={(err) => console.error(err)}
    />
  )
}

Props

SendBsv21

PropTypeDefaultDescription
balancesTokenBalance[][]Available token balances for the selector
onSend(params: SendBsv21Params) => Promise<SendBsv21Result>--Callback to execute the token transfer
onSuccess(result: SendBsv21Result) => void--Called on successful send
onError(error: Error) => void--Called on error
classNamestring--Additional CSS classes

TokenBalance

interface TokenBalance {
  tokenId: string
  symbol: string
  balance: string
  decimals: number
  iconUrl?: string
}

SendBsv21Params

interface SendBsv21Params {
  tokenId: string
  amount: string   // Raw integer string (accounting for decimals)
  address: string
}

SendBsv21Result

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