BEEF
Overview
Purpose
Basic Usage
Creating a BEEF Package
import { Beef, Transaction, MerklePath } from '@bsv/sdk';
// Create a BEEF package
const beef = new Beef();
// Add transactions to the package
const parentTx = Transaction.fromHex('0100000001...');
const childTx = Transaction.fromHex('0100000001...');
beef.addTransaction(parentTx);
beef.addTransaction(childTx);
// Add merkle proof for SPV validation
const merklePath = MerklePath.fromHex('fed7c509000a02fddd01...');
beef.addMerklePath(merklePath);
// Serialize to hex for transmission
const beefHex = beef.toHex();
console.log('BEEF package:', beefHex);
// Parse BEEF package
const parsedBeef = Beef.fromHex(beefHex);
console.log('Transactions:', parsedBeef.getTransactions());Verifying a BEEF Package
Key Features
1. Transaction Bundle Creation
2. Merkle Proof Integration
3. Version 1 and Version 2 Formats
4. Atomic Transaction Validation
API Reference
Constructor
Static Methods
Beef.fromBinary(binary: number[]): Beef
Beef.fromHex(hex: string): Beef
Instance Methods
addTransaction(tx: Transaction): void
addMerklePath(path: MerklePath): void
getTransactions(): Transaction[]
verify(chainTracker: ChainTracker): Promise<boolean>
toBinary(): number[]
toHex(): string
Instance Properties
Common Patterns
Pattern 1: Payment Channel Transaction Bundle
Pattern 2: Atomic Multi-Party Transaction
Pattern 3: Transaction Chain Archival
Security Considerations
Performance Considerations
Related Components
Code Examples
Best Practices
Troubleshooting
Issue: BEEF verification fails with valid transactions
Issue: BEEF package too large
Issue: Transaction ordering errors
Issue: Missing merkle proofs
Further Reading
Status
Last updated
