BigBlocks

Deploy Token

Deploy a BSV21 fungible token to the BSV blockchain with symbol, supply, decimal precision, and an icon image

A self-contained block for deploying BSV21 fungible tokens. Manages form state, icon upload with live preview, fee estimation, and deploy execution through a clean onDeploy callback. The underlying useDeployToken hook is also exported for headless usage.

Installation

bunx shadcn@latest add https://registry.bigblocks.dev/r/deploy-token.json

Usage

import { DeployToken, type DeployTokenParams, type DeployTokenResult } from "@/components/blocks/deploy-token"
import { deployBsv21Token } from "@1sat/core"
 
export default function DeployTokenPage() {
  const handleDeploy = async (params: DeployTokenParams): Promise<DeployTokenResult> => {
    try {
      const tx = await deployBsv21Token({
        symbol: params.symbol,
        decimals: params.decimals,
        icon: {
          dataB64: params.iconBase64,
          contentType: params.iconContentType,
        },
        initialDistribution: {
          address: myAddress,
          tokens: Number(params.maxSupply),
        },
        destinationAddress: myAddress,
        utxos: paymentUtxos,
      })
      return { txid: tx.id("hex") }
    } catch (err) {
      return { error: err instanceof Error ? err.message : "Deploy failed" }
    }
  }
 
  return (
    <DeployToken
      onDeploy={handleDeploy}
      onSuccess={(result) => console.log("Deployed:", result.txid)}
      onError={(error) => console.error(error)}
      defaults={{ defaultMaxSupply: "21000000", defaultDecimals: 8 }}
    />
  )
}

API Reference

DeployToken

PropTypeDefaultDescription
onDeploy(params: DeployTokenParams) => Promise<DeployTokenResult>Required. Executes the on-chain deploy action.
onSuccess(result: DeployTokenResult) => voidCalled after a successful deployment.
onError(error: Error) => voidCalled when deployment fails.
defaultsUseDeployTokenOptionsDefault values for the form fields.
classNamestringAdditional CSS classes applied to the outer card.

DeployTokenParams

interface DeployTokenParams {
  symbol: string           // Token ticker symbol
  maxSupply: string        // Raw integer string, no separators
  decimals: number         // 0–18
  iconBase64: string       // Raw base64 (no data: prefix)
  iconContentType: string  // MIME type of the icon image
}

DeployTokenResult

interface DeployTokenResult {
  txid?: string   // Transaction ID on success
  rawtx?: string  // Raw transaction hex (optional)
  error?: string  // Error message when deploy failed
}

UseDeployTokenOptions

Pass as defaults to pre-populate form fields.

FieldTypeDefaultDescription
defaultSymbolstring""Initial token symbol.
defaultMaxSupplystring"21000000"Initial max supply.
defaultDecimalsnumber8Initial decimal precision (0–18).

Hook

Use useDeployToken directly when you need a custom UI.

import { useDeployToken } from "@/components/blocks/deploy-token"
 
function CustomDeployForm() {
  const token = useDeployToken({ defaultMaxSupply: "1000000" })
 
  return (
    <form onSubmit={(e) => {
      e.preventDefault()
      token.deploy(async (params) => {
        // call your deploy function
        return { txid: "..." }
      })
    }}>
      <input
        value={token.form.symbol}
        onChange={(e) => token.setSymbol(e.target.value)}
        placeholder="TOKEN"
      />
      <p>Estimated fee: {token.feeEstimate} sats</p>
      <button type="submit" disabled={!token.isValid || token.isDeploying}>
        Deploy
      </button>
    </form>
  )
}

UseDeployTokenReturn

PropertyTypeDescription
formDeployTokenFormStateCurrent form values for binding to UI inputs.
isValidbooleanWhether all required fields are filled.
isDeployingbooleanWhether a deploy is in progress.
feeEstimatenumberEstimated fee in satoshis (0 until icon is selected).
resultTxidstring | nullTransaction ID after successful deploy.
errorMessagestring | nullError message from the most recent attempt.
setSymbol(value: string) => voidUpdate the symbol field.
setMaxSupply(value: string) => voidUpdate the max supply field.
setDecimals(value: string) => voidUpdate the decimals field.
selectIcon(file: File) => voidSelect and preview an icon file.
removeIcon() => voidClear the selected icon.
deploy(handler: (params: DeployTokenParams) => Promise<DeployTokenResult>) => Promise<void>Execute the deploy with a provided handler.