BRC-29
Overview
Purpose
Basic Usage
Creating a Payment Request
import { PaymentRequest, P2PKH } from '@bsv/sdk';
// Create payment request
const paymentRequest: PaymentRequest = {
network: 'mainnet',
outputs: [
{
script: new P2PKH().lock('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa').toHex(),
satoshis: 10000,
description: 'Digital content purchase'
}
],
creationTimestamp: Date.now(),
expirationTimestamp: Date.now() + (3600 * 1000), // 1 hour
memo: 'Payment for article #12345',
merchantData: JSON.stringify({
orderId: '12345',
customerId: 'user_abc',
items: ['article-xyz']
})
};
console.log('Payment request created');
console.log('Amount:', paymentRequest.outputs[0].satoshis, 'satoshis');
console.log('Expires:', new Date(paymentRequest.expirationTimestamp));Creating a Payment Response
Key Features
1. PaymentRequest Structure and Creation
2. PaymentResponse with SPV Envelopes
3. Direct Payment Negotiation
4. Reference Implementation Patterns
API Reference
PaymentRequest Interface
PaymentResponse Interface
Helper Functions
createPaymentRequest(params): PaymentRequest
createPaymentRequest(params): PaymentRequestverifyPaymentResponse(request, response, chainTracker): Promise<VerificationResult>
verifyPaymentResponse(request, response, chainTracker): Promise<VerificationResult>Common Patterns
Pattern 1: E-commerce Checkout Integration
Pattern 2: Content Paywall with BRC-29
Pattern 3: Peer-to-Peer Marketplace
Security Considerations
Performance Considerations
Related Components
Code Examples
Best Practices
Troubleshooting
Issue: Payment verification fails with correct payment
Issue: Payment request expired before user could pay
Issue: BEEF envelope too large for HTTP request
Issue: Cannot parse merchantData from old requests
Further Reading
Status
Last updated
