npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@directcryptopay/sdk

v0.3.1

Published

Official SDK for DirectCryptoPay — accept crypto payments directly to your wallet. Non-custodial, multi-chain, developer-first.

Downloads

738

Readme

@directcryptopay/sdk

Official SDK for DirectCryptoPay — accept crypto payments directly to your wallet. Non-custodial, multi-chain, developer-first.

Features

  • Non-custodial — Funds go directly from customer wallet to yours
  • Multi-chain — Ethereum, Polygon, BNB Chain, Base, Arbitrum, Optimism (mainnet + testnet)
  • Lightweight — ~5 KB bundle, opens checkout in an iframe overlay (like Stripe Checkout)
  • WalletConnect support — MetaMask, Rabby, WalletConnect, and 300+ wallets
  • Two payment modes — Tool-based (pre-configured) or Integration-based (dynamic amounts)
  • TypeScript-first — Full type safety with exported types

Installation

npm install @directcryptopay/sdk
# or
pnpm add @directcryptopay/sdk
# or
yarn add @directcryptopay/sdk

Quick Start

1. Initialize the SDK

Call DCP.init() once when your app loads.

import { DCP } from '@directcryptopay/sdk';

DCP.init({
  // Optional: defaults to 'https://directcryptopay.com'
  // checkoutUrl: 'https://preview.directcryptopay.com',
});

2. Accept a payment

Option A: Payment Tool (pre-configured amount, token, and chain)

DCP.pay({
  toolId: 'your-tool-id', // From Dashboard > Payment Tools > Get Code
  callbacks: {
    onSuccess: (data) => {
      console.log('Payment confirmed:', data.txHash);
    },
    onError: (error) => {
      console.error('Payment failed:', error);
    },
  },
});

Option B: Integration (dynamic amount, token selector)

DCP.Payment({
  integrationId: 'your-integration-id',
  amount_usd: '49.99',
  callbacks: {
    onSuccess: (data) => {
      console.log('Paid:', data.txHash);
    },
  },
});

API Reference

DCP.init(config)

Initialize the SDK. Must be called once before pay() or Payment().

DCP.init({
  checkoutUrl?: string;   // Default: 'https://directcryptopay.com'
  projectId?: string;     // Deprecated — no longer needed
  env?: 'test' | 'prod';
});

DCP.pay(options)

Open the checkout iframe for a pre-configured Payment Tool.

DCP.pay({
  toolId: string;               // Required — Payment Tool ID
  amountUsd?: number;           // Override USD amount (for donations)
  callbacks?: PaymentCallbacks;
});

DCP.Payment(options)

Open the checkout iframe for an Integration-based payment.

DCP.Payment({
  integrationId: string;                   // Required — Integration public ID
  amount_usd?: string;                     // Amount in USD (e.g., '49.99')
  amount?: string | number;                // OR amount in token units (not both)
  currency?: string;                       // Pre-select token (skips selector)
  chainId?: number;                        // Pre-select chain
  metadata?: Record<string, any>;          // Custom metadata
  callbacks?: PaymentCallbacks;
});

Note: Provide either amount_usd or amount, not both.

DCP.close()

Programmatically close the checkout iframe.

Callbacks

All callbacks are optional.

interface PaymentCallbacks {
  onOpen?: () => void;                                          // Iframe opened
  onClose?: () => void;                                         // Iframe closed
  onTxSubmitted?: (txHash: string) => void;                     // Transaction sent
  onSuccess?: (data: { txHash: string; intentId?: string }) => void;  // Payment confirmed
  onCancel?: () => void;                                        // User cancelled
  onError?: (error: Error) => void;                             // Error occurred
}

Framework Examples

Next.js (App Router)

1. Create a provider:

// components/DCPProvider.tsx
'use client';

import { useEffect } from 'react';

export function DCPProvider({ children }: { children: React.ReactNode }) {
  useEffect(() => {
    import('@directcryptopay/sdk').then(({ DCP }) => {
      DCP.init({});
    });
  }, []);

  return <>{children}</>;
}

2. Wrap your layout:

// app/layout.tsx
import { DCPProvider } from '@/components/DCPProvider';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        <DCPProvider>{children}</DCPProvider>
      </body>
    </html>
  );
}

3. Create a pay button:

// components/PayButton.tsx
'use client';

import { useState } from 'react';

export function PayButton({ toolId, label = 'Pay with Crypto' }: {
  toolId: string;
  label?: string;
}) {
  const [status, setStatus] = useState<string | null>(null);

  const handlePay = async () => {
    setStatus('pending');
    const { DCP } = await import('@directcryptopay/sdk');
    DCP.pay({
      toolId,
      callbacks: {
        onSuccess: () => setStatus('confirmed'),
        onError: () => setStatus('failed'),
        onClose: () => setStatus(null),
      }
    });
  };

  return (
    <button onClick={handlePay} disabled={status === 'pending'}>
      {status === 'confirmed' ? 'Payment Confirmed!' :
       status === 'pending' ? 'Processing...' : label}
    </button>
  );
}

Vanilla JavaScript

<script type="module">
  import { DCP } from 'https://unpkg.com/@directcryptopay/sdk/dist/index.js';

  DCP.init({});

  document.getElementById('pay-btn').addEventListener('click', () => {
    DCP.pay({
      toolId: 'your-tool-id',
      callbacks: {
        onSuccess: (data) => alert('Payment confirmed!'),
        onError: (error) => alert('Payment failed: ' + error.message),
      }
    });
  });
</script>

How It Works

When DCP.pay() or DCP.Payment() is called, the SDK opens an iframe overlay pointing to the DirectCryptoPay checkout page. The checkout page handles:

  1. Wallet connection (MetaMask, Rabby, WalletConnect, etc.)
  2. Smart token detection and balance display
  3. Network switching
  4. Transaction signing and submission
  5. On-chain verification

The SDK communicates with the iframe via postMessage and maps events to your callbacks. This architecture keeps the SDK lightweight (~5 KB) while providing the full checkout experience.

Security

The frontend callbacks (onSuccess, onError) are for UX purposes only. For production apps, always verify payments server-side using webhooks.

DirectCryptoPay is non-custodial: transactions go directly from the customer's wallet to your wallet address. No funds are held by DirectCryptoPay at any point.

Migrating from v0.2.x

v0.3.0 is a major refactor. The public API is the same, but:

  • DCP.init({ projectId })projectId is no longer required (can be omitted)
  • DCP.init({ checkoutUrl }) — new option to customize checkout URL
  • onStatus callback removed — use onTxSubmitted and onSuccess instead
  • Bundle size reduced from ~3 MB to ~5 KB

Links

License

MIT