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

@sundaeswap/capacity-exchange-providers

v3.0.3

Published

Capacity Exchange providers for midnight transactions

Readme

@sundaeswap/capacity-exchange-providers

Browser APIs for the Capacity Exchange.

To submit a transaction to the Midnight Blockchain, you need to pay for it in DUST. The Capacity Exchange lets users fund transactions without any DUST of their own. The capacityExchangeWalletProvider requires users to pay for this DUST with some other currency. The sponsoredTransactionsWalletProvider doesn't require users to pay at all.

If you are using React, consider using @sundaeswap/capacity-exchange-react-sdk for an easier integration experience.

Usage

For more complete example usage, see our React example app.

import {
  CurrencySelectionResult,
  ExchangePrice,
  Offer,
  OfferConfirmationResult,
  capacityExchangeWalletProvider,
  indexerChainStateProvider,
  sponsoredTransactionsWalletProvider,
} from '@sundaeswap-capacity-exchange-providers';

async function chooseFirstCurrency(
  prices: ExchangePrice[],
  dustRequired: bigint,
  requestId: string,
): Promise<CurrencySelectionResult> {
  console.log(`${requestId}: we need ${dustRequired} dust`)
  for (const price of prices) {
  }
  if (prices.length) {
    const exchangePrice = prices[0];    
    console.log(`${requestId}: paying ${exchangePrice.price.amount} ${exchangePrice.price.currency}`);
    return { status: 'selected', exchangePrice };
  } else {
    return { status: 'cancelled' };
  }
}

async function alwaysConfirmOffer(
  offer: Offer,
  dustRequired: bigint,
  requestId: string,
): Promise<OfferConfirmationResult> {
  console.log(`${requestId}: confirming offer ${offer.offerId}`);
  return { status: 'confirmed' };
}

async function getWalletProvider(wallet: ConnectedAPI) {
  const [addresses, configuration] = await Promise.all([
    wallet.getShieldedAddresses(),
    wallet.getConfiguration(),
  ]);
  return capacityExchangeWalletProvider({
    networkId: configuration.networkId,
    coinPublicKey: addresses.shieldedCoinPublicKey,
    encryptionPublicKey: addresses.shieldedEncryptionPublicKey,
    balanceUnsealedTransaction: wallet.balanceUnsealedTransaction,
    balanceSealedTransaction: wallet.balanceSealedTransaction,
    chainStateProvider: indexerChainStateProvider(configuration.indexerUri, configuration.indexerWsUri),
    promptForCurrency: chooseFirstCurrency,
    confirmOffer: alwaysConfirmOffer,
  });
}

async function getSponsoredWalletProvider(wallet: ConnectedAPI) {
  const addresses = await wallet.getShieldedAddresses();
  return sponsoredTransactionsWalletProvider({
    coinPublicKey: addresses.shieldedCoinPublicKey,
    encryptionPublicKey: addresses.shieldedEncryptionPublicKey,
    capacityExchangeUrl: 'https://capacity-exchange.my.dapp'
  });
}

API

capacityExchangeWalletProvider(config)

A function which gives you a WalletProvider backed by the Capacity Exchange. This provider balances Midnight transactions through the Capacity Exchange API; the user will pay with some other currency instead of DUST.

If you would like to provide DUST for user transactions yourself, consider the sponsoredTransactionsWalletProvider instead.

| Argument | Required | Description | | --- | --- | --- | | config.networkId | yes | The ID of the midnight network you're connecting to. Usually preview, preprod, or mainnet. | config.coinPublicKey | yes | The coinPublicKey of the user's Shielded wallet. | | config.encryptionPublicKey | yes | The encryptionPublicKey of the user's Shielded wallet. | | config.balanceUnsealedTransaction | yes | A callback which can balance an unsealed transaction. You can pass balanceUnsealedTransaction from the user's wallet. | | config.balanceSealedTransaction | yes | A callback which can balance a sealed transaction. You can pass balanceSealedTransaction from the user's wallet. | | config.chainStateProvider | yes | A ChainStateProvider, used to query the on-chain CES registry for registered server URLs and to fetch current LedgerParameters for DUST speck cost estimation. Most dApps can pass indexerChainStateProvider(indexerUri, indexerWsUri), which builds one backed by a Midnight indexer. | | config.additionalCapacityExchangeUrls | no | The URLs for any additional Capacity Exchange servers to use. | | config.margin | no | A safety margin in blocks, used when estimating fees. Defaults to 3. | | config.promptForCurrency | yes | A function called when the user must choose which currency to pay. | | config.confirmOffer | yes | A function called when the user has received an offer and must confirm it's acceptable. |

config.promptForCurrency(prices, dustRequired, requestId)

This callback is called when the user must choose which currency to pay. It can return the following:

  • { status: 'selected', exchangePrice }: The user will pay the given price.
  • { status: 'cancelled' }: The user will not pay, and will not submit the transaction.

config.confirmOffer(offer, dustRequired, requestId)

This callback is called when the user must confirm a given offer. It can return the following:

  • { status: 'confirmed' }: The user will accept the given offer.
  • { status: 'back' }: The user will not accept the given offer, but would like to choose a different currency to pay with.
  • { status: 'cancelled' }: The user will not accept the given offer, and will not submit the transaction.

sponsoredTransactionsWalletProvider(config)

A function which gives you a WalletProvider used to "sponsor" transactions. These are transactions which a Capacity Exchange server funds for free.

To use this wallet provider, you will probably want to run your own server. See the server documentation for more on that.

| Argument | Required | Description | | --- | --- | --- | | config.coinPublicKey | yes | The coinPublicKey of the user's Shielded wallet. | | config.encryptionPublicKey | yes | The encryptionPublicKey of the user's Shielded wallet. | | config.capacityExchangeUrl | yes | The URL to a Capacity Exchange server willing to fund this transaction. This will probably be run by the dApp developer.|