Client Library SDK
Client library v5.4.0 development guide
Last updated
Was this helpful?
Client library v5.4.0 development guide
Last updated
Was this helpful?
The zkbob-client-js
library SDK is used to interact with the zkBob ecosystem from the client side. The SDK supports different privacy pool deployments and can be used to create custom clients.
The latest stable version of the library is published on with the latest
tag. To use the library install it with your preferred packet manager like npm
:
or yarn
:
...or manually include it in the package.json
file as follows:
All interactions with the solution are performed within the instance of the ZkBobClient
object which should be initialized with the desired . There are two available modes for the ZkBobClient
instance:
Account-less mode. The library can interact with most of the system components (such as relayers, contracts and so on) to retrieve publicly available data (transaction fee, limits, Merkle tree indexes and other data needed to render the UI), but cannot perform any actions belonging to the concrete user account (e.g. getting user's balance, making deposits\transfers\withdrawals and so on). The library starts on this state when the ZkBobClient
is .
Full mode. To switch to full mode you must provide user credentials (spending key) to the library. Do this by a prepared user's . of the account any time
Start with the Configuration section to understand which data you need start designing your own client.
You can always refer to the existing client implementations to get a better understanding and find answers to your questions:
Waiting for your cool implementation to include it here...!
You can build a custom client for the platform of your choice or add extended functionality like a custodial wallet service or mobile wallet. It should also be noted that the SDK relies heavily on underlying low-level Rust code compiled to WASM, so for example mobile support in React Native would impose additional challenges.
In order for a client to create a valid transaction proof, parameters and a verification key are required (for a quick sanity check before sending a transaction). These parameters are generated using a trusted setup ceremony for production usage, while the development environment uses some random values.
All the testing and development environments on testnets use the following parameters:
All of the production environments use these parameters:
The CDN is configured so that only requests from localhost and zkbob domains are processed, so you would have to download params files and include them in the bundle. You can see how to do that in the Examples
Currently the API between the front end and the SDK allows you to pass the account credentials in the form of a spending key that is derived from the mnemonic seed phrase. You can export your seed phrase and pass it to the function deriveSpendingKeyZkBob
to get a secret key:
Then pass the resulting spending key to the accountConfig
object to login.
If you'd rather derive a spending key from your Web3 wallet (such as MetaMask) signature then you need to get the menmonic first:
In the current version of the protocol, only the user can generate a new address for receiving funds inside the pool (zkAddress). Generating a zkAddress requires a secret encryption key which can only be provided by the user. Address generation itself is very easy, simply call the corresponding method of the client object.
Associated examples are available for and configurations.
Actual production and development configurations are available for .
a ZkBobClient
instance and check that the account-less mode works properly. For example you can or . All available functions for this mode are described in the Account-less Mode Operations section.
Create you own and it to the ZkBobClient
instance. Remember only one account can be attached at a time.
the local state with the relayer and privacy pool state. This operation can take some time depending on pool size (overall number of transactions in the pool).
Retrieve account related data (e.g. or ). All routines associated with the account are located in the Full Mode Operations section
located in the client repository's README file.
- a simple text Web-client based on jQuery Terminal. It's always synced with the last library version.
- a React App template project with integrated zkbob-client-js
library.
The SDK can be imported as a regular JS library, but it requires some customization of the webpack configuration, which can be challenging if you use create-react-app
. This is why we have created a ready-to-go that utilizes react-app-rewired tool to override some configurations and make it all work.
Alternatively you can use Next.js or Vite to bootstrap your React app that allows you to access the webpack configuration.