Token Fundamentals
Build a token management interface using BSV SDK's PushDrop, WalletClient, and MessageBox.
What You'll Build
Token minting with PushDrop (BRC-48)
P2P transfers via MessageBox (BRC-33)
Balance tracking with UTXO aggregation
Two-phase transaction signing
Token Structure (3 fields):
[
tokenId, // UTF-8: '___mint___' or 'txid.vout'
amount, // Uint64LE (8 bytes)
metadata // JSON string
]📦 Complete Code Example
The full working implementation of this token frontend is available on GitHub:
Repository: github.com/sirdeggen/demo-day/tree/main/tokenization
Frontend Code:
/frontendfolderOverlay Service Code:
/overlayfolder
You can clone the repository and explore the complete implementation alongside this tutorial.
Setup
Create .env:
1. Wallet Context
src/context/WalletContext.tsx:
BSV SDK Pattern: WalletClient connects to BSV Desktop Wallet automatically. No API keys needed.
2. Token Minting
src/components/CreateTokens.tsx:
Critical Points:
'___mint___'marker creates new token → tokenId becomestxid.voutcustomInstructionsstores derivation params (required for spending)randomizeOutputs: falseensures predictable output indices
Reference: BRC-48: PushDrop, BRC-42: Key Derivation
3. Balance Viewer
src/components/TokenWallet.tsx:
Pattern: Aggregate all UTXOs by tokenId to get total balance per token type.
4. Token Transfer (Two-Phase Signing)
src/components/SendTokens.tsx:
Two-Phase Signing:
createAction()- Wallet adds BSV inputs, estimates unlock lengthManual signing - Create PushDrop unlock scripts using
customInstructionssignAction()- Submit completed unlocking scripts
Reference: BRC-62: BEEF, BRC-33: MessageBox
5. Token Receiving
src/components/ReceiveTokens.tsx:
Pattern: internalizeAction imports transaction with derivation params for future spending.
Key Concepts
Privacy (BRC-42)
Every token output uses a unique derived address:
Random
keyIDper output prevents address reuseCannot link UTXOs to same owner
BEEF Format (BRC-62)
Transactions include parent txs + merkle proofs for SPV validation without full blockchain.
Critical: customInstructions
MUST store derivation params to spend tokens:
Without this, tokens are permanently unspendable.
Troubleshooting
"Failed to connect" - Install/unlock BSV Desktop Wallet
"Insufficient balance" - Need BSV for tx fees (get testnet coins from faucet)
Tokens not appearing - Check correct basket name, verify
customInstructionsstored
Resources
Last updated
