NFT Subscription SDK

Component Library

Pre-built React components designed to accelerate your subscription NFT integration. Copy, paste, and customize to match your brand.

Installation

pnpm add @nft-sub/components @nft-sub/sdk
TypeScript support
Fully tested
Production ready

SubscriptionWidget

All-in-one subscription management component

Props

PropTypeDescription
merchantIdbigintThe merchant ID to subscribe to
classNamestring?Optional CSS class names
onSuccess(txHash: string) => voidCallback on successful subscription
onError(error: Error) => voidCallback on error

Example Usage

component.tsx
<SubscriptionWidget
  merchantId={1n}
  onSuccess={(txHash) => console.log('Success:', txHash)}
  onError={(error) => console.error('Error:', error)}
/>

PaymentForm

Flexible payment form with multiple token support

Props

PropTypeDescription
supportedTokensstring[]Array of supported payment tokens
defaultTokenstringDefault selected token
onSubmit(token: string, amount: bigint) => voidSubmit handler
loadingboolean?Loading state indicator

Example Usage

component.tsx
<PaymentForm
  supportedTokens={['ETH', 'USDC', 'DAI']}
  defaultToken="ETH"
  onSubmit={(token, amount) => handlePayment(token, amount)}
  loading={isProcessing}
/>

AccessGate

Conditional rendering based on subscription status

Props

PropTypeDescription
merchantIdbigintMerchant ID to check access for
childrenReactNodeContent to show when access is granted
fallbackReactNode?Content to show when access is denied
loadingReactNode?Content to show while checking access

Example Usage

component.tsx
<AccessGate 
  merchantId={1n}
  fallback={<SubscribePrompt />}
  loading={<Spinner />}
>
  <PremiumContent />
</AccessGate>

StatusIndicator

Visual subscription status display

Props

PropTypeDescription
status'active' | 'expired' | 'none'Current subscription status
expiresAtDate?Expiration date for active subscriptions
showDetailsboolean?Show detailed information
compactboolean?Use compact display mode

Example Usage

component.tsx
<StatusIndicator
  status="active"
  expiresAt={new Date('2024-12-31')}
  showDetails={true}
/>

Best Practices

1

Handle Loading States

Always provide visual feedback during blockchain transactions

2

Error Boundaries

Wrap components in error boundaries to gracefully handle failures

3

Optimize Re-renders

Use React.memo and useMemo for expensive computations

4

Accessibility First

Ensure all interactive elements are keyboard navigable and screen reader friendly