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

@rakelabs/dpayments-sdk

v0.1.0

Published

npm SDK for Disputable Payments workflows

Downloads

12

Readme

@rakelabs/dpayments-sdk

Add on-chain payments with built-in Kleros arbitration to your product. No blockchain expertise required.

What is this?

DPayments is a JavaScript / TypeScript library for holding payments between two parties using Ethereum smart contracts. Think of it as a programmable payment with a built-in dispute system:

  • A payer sends funds (ETH or ERC20) into a smart contract.
  • A payee claims the funds after a settlement time, or refunds voluntarily.
  • If there's a disagreement, either party raises a Kleros dispute, where jurors decide the outcome.
  • Rulings are enforced automatically on-chain.

This library never touches your users' money. It prepares unsigned transactions. Your app hands them to the user's wallet (MetaMask, WalletConnect). The user signs and submits. Your server never holds private keys.

Your app  ──→  dpayments SDK  ──→  unsigned transaction  ──→  User's wallet  ──→  Blockchain
              (prepares it)       (just instructions)         (signs it)         (executes it)

Installation

npm install @rakelabs/dpayments-sdk ethers

Requires ethers v6. ethers v5 is not compatible.

Payment lifecycle

The lifecycle covers payment, settlement, and optional dispute resolution.

Quick start

import { DPayments } from '@rakelabs/dpayments-sdk';
import { BrowserProvider } from 'ethers';

const provider    = new BrowserProvider(window.ethereum);
await provider.send('eth_requestAccounts', []);
const signer      = await provider.getSigner();
const myAddress   = await signer.getAddress();

// One line. Chain and factory address are auto-detected.
const dpayments = await DPayments.fromProvider(provider, myAddress);

Happy path: ETH payment in 4 steps

import { DPayments } from '@rakelabs/dpayments-sdk';
import { BrowserProvider } from 'ethers';

// ─── Setup ────────────────────────────────────────────────────────────────────

const provider    = new BrowserProvider(window.ethereum);
await provider.send('eth_requestAccounts', []);
const signer      = await provider.getSigner();
const payerWallet = await signer.getAddress();

const dpayments = await DPayments.fromProvider(provider, payerWallet);

const payeeAddress = '0xPAYEE_WALLET_ADDRESS';

// ─── Step 1: Create and fund the payment ─────────────────────────────────────
//
// prepareCreateEthPayment quotes the fee and builds the transaction.
// ETH is sent with the transaction: gross = net + fee.
// The payment is funded immediately on-chain.

const tinyAmount = 1_000_000n; // 0.000001 ETH in wei

const now      = BigInt(Math.floor(Date.now() / 1000));
const settleAt = now + 60n; // 60 seconds from now

const { tx: createTx, paymentId } = await dpayments.factory.prepareCreateEthPayment({
  netAmount:              tinyAmount,
  payeeAddress,
  settlementTimeUnixSec:  settleAt,
});

// ─── Step 2: Find the deployed payment ───────────────────────────────────────

const logs   = await dpayments.factory.getLogs(0, 'latest');
const ourLog = logs.find(e => e.paymentId === paymentId)!;
const payment = dpayments.dPayment(ourLog.paymentAddress);

// ─── Step 3: Wait for settlement, then payee claims ─────────────────────────

//   await payeeSigner.sendTransaction(payment.settle());

await new Promise(r => setTimeout(r, 61_000));
await signer.sendTransaction(payment.settle());
// → Settled

The complete dispute lifecycle (rulings, appeals, and evidence) mirrors the Klescrow escrow pattern. See docs/disputes.md.

Decoding revert errors

When a transaction reverts on-chain, MetaMask shows a raw hex code. decodeDPaymentError turns it into a readable error name.

import { decodeDPaymentError } from '@rakelabs/dpayments-sdk';

try {
  await signer.sendTransaction({ ...tx, value: BigInt(tx.value) });
} catch (err) {
  const decoded = decodeDPaymentError(err);

  if (decoded && 'error' in decoded) {
    // "InvalidState", "NotPayer", "BadEthValue" …
    showToast(`Transaction reverted: ${decoded.error}`);
    console.log('Args:', decoded.args); // { sent: 100n, expectedMin: 200n }
  } else if (decoded && 'raw' in decoded) {
    // Unrecognized revert: surface the hex
    console.warn('Unknown revert:', decoded.raw);
  }
  // decoded === null → not a contract revert (network error, user rejected, etc.)
}

Full reference: docs/error-decoder.md.

Further reading

| Doc | Content | |-----|---------| | docs/disputes.md | Raising disputes, evidence, appeals, and rulings | | docs/reference.md | Every action, type, event topic, and common mistake | | docs/error-decoder.md | decodeDPaymentError reference and all error types | | docs/advanced.md | Transaction builder, reader, multicall, implementation selection |

Smart Contract Disclosure

This software instantiates autonomous, immutable contracts. The author has zero administrative control or upgrade authority post-deployment. Users interact with this software entirely at their own risk.