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 🙏

© 2025 – Pkg Stats / Ryan Hefner

icptopup-ts

v0.0.1

Published

TypeScript agent for programmatically topping up canisters via ICPTopup

Readme

icptopup-ts

TypeScript agent for programmatically topping up canisters via ICPTopup

Topping up canisters from ICP

ICPTopup allows you to easily send cycles to up to 100 canisters at once.

1. To get started, first install icptopup-ts

npm i icptopup-ts

2. Approve ICPTopup to mint cycles from ICP on your behalf

import ICPTopup from "icptopup-ts";

// in your function
const agent = HttpAgent.createSync({ identity, host: "https://ic0.app" });
const approvalBlockIndex = await ICPTopup.approveToSpendE8s({
  agent,
  e8sToApprove: BigInt(1e7), // approve a minimum of 0.1 ICP
});

3. Instantiate the ICPTopup Actor

In the agent, pass the identity that previously approved ICP to be spent by the ICPTopup service, and target the ICP mainnet host, https://ic0.app

const agent = HttpAgent.createSync({ identity, host: "https://ic0.app" });
const icpTopupActor = new ICPTopup(agent);

4. Call ICPTopup's synchronous batchTopupSync() API, or its asynchronous topup API.

Both synchronous and asynchronous APIs allow you to specify: e8sToTransfer - ICP transferred for minting cycles topupTargets - the canisters being topped up.

The topupProportion in each topup target allows you to specify how much of the minted cycles you want to send to each canister. In the example below, there are 3 proportions total (2 + 1), and so 2/3rds of the minted cycles are being sent to the first canister, and 1/3rd of the minted cycles are sent to the second canister.

  const result = await icpTopupActor.batchTopupSync({
    // Note: make sure the icp account spent from has enough e8s for the ledger transfer (10_000 e8s)
    e8sToTransfer: BigInt(1e7), // 0.1 ICP
    topupTargets: [
      {
        canisterId: Principal.fromText("qc4nb-ciaaa-aaaap-aawqa-cai"),
        topupProportion: 2n, // send up 2/3rds of the minted cycles here
      },
      {
        canisterId: Principal.fromText("gf3bz-2aaaa-aaaap-ahngq-cai"),
        topupProportion: 1n, // send 1/3rd of the minted cycles here
      },
    ],
  });

Check your ICPTopup account allowance

The ICPTopup.checkAllowance() API provides a simple wrapper determining your ICP allowance with ICPTopup

  const allowance = await ICPTopup.checkAllowance({
    account: {
      owner: identity.getPrincipal(),
      subaccount: [],
    },
  });

Perform an asynchronous topup

ICPTopup usually takes 20-30 seconds to complete a topup.

While the synchronous batchTopupSync() API executes topups synchronously leaving the caller waiting for a response, the batchTopupAsync() API immediately returns a request identifier that can be used to immediately poll for the result of the topup.

Kicking off an asynchronous topup is nearly identical to a synchronous one.

  // Kick off the topup
  const result = await icpTopupActor.batchTopupAsync({
    e8sToTransfer: BigInt(1e7), // 0.1 ICP
    topupTargets: [
      {
        canisterId: Principal.fromText("qc4nb-ciaaa-aaaap-aawqa-cai"),
        topupProportion: 1n, // send up 1/2 of the minted cycles here
      },
      {
        canisterId: Principal.fromText("gf3bz-2aaaa-aaaap-ahngq-cai"),
        topupProportion: 1n, // send 1/2 of the minted cycles here
      },
    ],
  });

And you can check the status of an asynchronous topup in two ways:

1. Check the latest status of the requestId with getLatestTopupRequestStatus()

  if (!("ok" in topupResponse)) {
    throw new Error(
      "Async topup failed to kick off with error: " + topupResponse.err,
    );
  }

  const requestId = topupResponse.ok; // request id associated with the topup
  const latestRequestStatus = await ICPTopup.getLatestTopupRequestStatus(requestId);

Or

2. Poll for the final topup result with pollAsyncStatusUntilComplete()

  await ICPTopup.pollAsyncStatusUntilComplete({
    requestId,
    pollIntervalInMs: 5000, // optional, defaults to 5sec
    logStatusUpdates: true, // optional, use if you want to output status update console logs
  });