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 🙏

© 2024 – Pkg Stats / Ryan Hefner

zkbob-client-js-dev

v3.2.0

Published

zkBob integration library

Downloads

1

Readme

zkbob-client-js

Example

import { ZkBobClient, ClientConfig, AccountConfig,
        ProverMode, TransferRequest, deriveSpendingKeyZkBob
    } from 'zkbob-client-js';


async function zkBobExample(): Promise<void> {
    // Client configuration includes set of pools, chains, parameters and other options
    const clientConfig: ClientConfig = {
      pools: {
          'BOB-sepolia': {
              'chainId': 11155111,
              'poolAddress': '0x3bd088C19960A8B5d72E4e01847791BD0DD1C9E6',
              'tokenAddress': '0x2C74B18e2f84B78ac67428d0c7a9898515f0c46f',
              'relayerUrls': ['https://relayer.thgkjlr.website/'],
              // external service to speed-up proof calculation, optional
              'delegatedProverUrls': [],
              // file with archived pool state
              // (optional, needed to reduce sync time)
              'coldStorageConfigPath': ''
          }
      },
      chains: {
          '11155111': {
              rpcUrls: ['https://rpc.sepolia.org'] // list of available JSON RPC endpoints
          },
      },
      snarkParams: {
          transferParamsUrl: '/path/to/transfer/params',  
          transferVkUrl: '/path/to/transfer/vk'
      },
      supportId: 'unique_string_generated_with_uuidv4',
      forcedMultithreading: undefined // multithreading config will be selected automatically
    };

    // creating a zkBob client without account to be worked on 'BOB-sepolia' pool
    const client = await ZkBobClient.create(clientConfig, 'BOB-sepolia');

    // now you can get relayer fee or pool limits for example
    const relayerFee = await client.atomicTxFee();
    console.log(`Relayer default fee: ${relayerFee} Gwei`);
    console.log(`Pool deposit total limit: ${(await client.getLimits(undefined)).deposit.total} Gwei`);

    // now let's attach account generated from the arbitrary 12-words mnemonic:
    const mnemonic = 'magic trophy foil direct marriage glad bench wash doctor risk end cheap';
    const accountConfig: AccountConfig = {
      // spending key is a byte array which derived from mnemonic
      sk: deriveSpendingKeyZkBob(mnemonic),
      // pool alias which should be activated
      pool: 'BOB-sepolia',
      // the account should have no activity (incoming notes including) before that index
      // you can use -1 value only for newly created account or undefined (or 0) for full state sync
      birthindex: 0,
      // using local prover
      proverMode: ProverMode.Local,
    };
    await client.login(accountConfig);

    // now the client is ready to send transactions, but let's get an account balance first
    // account state will be synced under-the-hood (pass false to getTotalBalance to prevent sync)
    console.log(`Shielded account balance: ${await client.getTotalBalance()} Gwei`);

    // let's generate our zkAddress to request a few tokens from somebody
    console.log(`My zk address: ${await client.generateAddress()}`);

    // and now let's transfer a few tokens inside the pool
    const tx: TransferRequest = {
      destination: 'zkbob_sepolia:HGkddpMXSfbXPEa8hUcttUaXpSPJihwA75q2Gue8QGxZtyDieqzb3iSRecdxS7d',  // shielded address
      amountGwei: BigInt('5000000000'), // 5 BOB
    }
    // returns an array of job ID for every transaction
    // (single transfer may produce several transactions to the pool)
    const jobIds = await client.transferMulti([tx], relayerFee);
    // wait while all transactions will be processed by relayer
    const result = await client.waitJobsTxHashes(jobIds);
    console.log(`${result.map((t) => `job #${t.jobId}: ${t.txHash}]`).join(`\n`)}`);

    // to close all connections to the indexed DBs invoke logout method:
    await client.logout();
}