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

@c7-digital/react

v0.0.6

Published

React hooks for Daml ledger integration using Canton JSON API v2

Readme

@c7-digital/react

React hooks for Daml ledger integration using Canton JSON API v2

Features

  • 🔧 Type-safe: Full TypeScript support with branded types from Canton API
  • Real-time: WebSocket streaming for live contract updates
  • 🎣 React Hooks: Modern React patterns with hooks for ledger operations
  • 📦 Lightweight: Minimal dependencies
  • Replacement: @daml/react.

Versioning

This package follows the Canton SDK versioning scheme, matching the @c7-digital/ledger package it depends on.

Current version: 3.3.0-snapshot.20250507.0

  • Versioned to match the Canton SDK and @c7-digital/ledger package
  • Ensures compatibility with the specific Canton OpenAPI types
  • When Canton releases a new version, both packages will be updated together

Version compatibility: Install the version that matches your Canton participant node version.

Installation

pnpm install @c7-digital/react @c7-digital/ledger

Build Output

The library builds to the dist/ folder with:

  • dist/index.js - Main entry point
  • dist/index.d.ts - TypeScript declarations
  • dist/**/*.d.ts.map - Source maps for debugging

Quick Start

1. Setup the Provider

Wrap your app with DamlLedger provider:

import { DamlLedger } from "@c7-digital/react";
import { Ledger } from "@c7-digital/ledger";

const ledger = new Ledger({
  baseUrl: "http://localhost:7575",
  token: "your-jwt-token",
  party: "Alice::1220...",
});

function App() {
  return (
    <DamlLedger ledger={ledger} party="Alice::1220...">
      <MyComponent />
    </DamlLedger>
  );
}

2. Query Contracts

Use useQuery to fetch active contracts:

import { useQuery } from "@c7-digital/react";

function MyComponent() {
  const { contracts, loading, error, reload } = useQuery(
    "#domain-verification-model:InternetDomainName:VerificationRequest"
  );

  if (loading) return <div>Loading...</div>;
  if (error) return <div>Error: {error.message}</div>;

  // Filter contracts at the application level
  const exampleContracts = contracts.filter(contract => contract.domain === "example.com");

  return (
    <div>
      <h2>Verification Requests ({exampleContracts.length})</h2>
      {exampleContracts.map((contract, i) => (
        <div key={i}>{contract.domain}</div>
      ))}
      <button onClick={reload}>Refresh</button>
    </div>
  );
}

3. Submit Commands

Use useLedger to get the ledger instance and useUser for the current user information:

import { useLedger, useUser } from "@c7-digital/react";

function ApprovalComponent({ contractId }: { contractId: string }) {
  const ledger = useLedger();
  const { user, loading, error } = useUser();

  const handleApprove = async () => {
    try {
      await ledger.exercise({
        templateId: "#domain-verification-model:InternetDomainName:VerificationRequest",
        contractId,
        choice: "AcceptRequest",
        choiceArgument: {
          dnsTxtPayload: "domain-verification=abc123",
        },
      });
    } catch (error) {
      console.error("Failed to approve:", error);
    }
  };

  if (loading) return <div>Loading user...</div>;
  if (error) return <div>Error: {error.message}</div>;

  return <button onClick={handleApprove}>Approve Request (as {user?.userId})</button>;
}

4. Real-time Streaming

Use useStreamQuery for live updates:

import { useStreamQuery } from "@c7-digital/react";

function LiveContracts() {
  const { contracts, loading, connected, error } = useStreamQuery(
    "#domain-verification-model:InternetDomainName:VerificationRequest"
  );

  return (
    <div>
      <div>Status: {connected ? "🟢 Connected" : "🔴 Disconnected"}</div>
      <div>Contracts: {contracts.length}</div>
      {contracts.map((contract, i) => (
        <div key={i}>{JSON.stringify(contract)}</div>
      ))}
    </div>
  );
}

API Reference

Components

DamlLedger

Provider component that enables ledger hooks.

interface DamlLedgerProps {
  ledger: Ledger;
  party: string;
  children: ReactNode;
}

Hooks

useQuery(templateId, options?)

Query active contracts for a template.

function useQuery<T>(templateId: string, options?: QueryOptions): QueryResult<T>;

interface QueryOptions {
  autoReload?: boolean;
}

interface QueryResult<T> {
  contracts: T[];
  loading: boolean;
  error: Error | null;
  reload: () => void;
}

useLedger()

Get the ledger instance.

function useLedger(): Ledger;

useUser()

Get the current user information from the token.

function useUser(): UserResult;

interface UserResult {
  user: User | null;
  loading: boolean;
  error: Error | null;
}

useStreamQuery(templateId, options?)

Stream active contracts with real-time updates.

function useStreamQuery<T>(templateId: string, options?: QueryOptions): StreamQueryResult<T>;

interface StreamQueryResult<T> extends QueryResult<T> {
  connected: boolean;
}

useStreamQueries(templateIds, options?)

Stream multiple templates simultaneously.

function useStreamQueries<T>(templateIds: string[], options?: QueryOptions): StreamQueryResult<T>;

useReload()

Get a function to reload all queries.

function useReload(): () => void;

Migration from @daml/react

This package provides a compatible API with @daml/react but uses the newer Canton JSON API v2:

| @daml/react | @c7-digital/react | Notes | | ------------------ | -------------------- | ------------------------------ | | DamlLedger | DamlLedger | Same API, different backend | | useParty() | useParty() | Identical | | useLedger() | useLedger() | Enhanced with typed operations | | useQuery() | useQuery() | Improved filtering and caching | | useStreamQuery() | useStreamQuery() | Real-time WebSocket updates |

License

Apache-2.0