Initialization
Now that you have your environment set up already, let's see about how to instantiate.
You can instantiate the SDK by passing it the CoreOptions object as an argument. Although, CoreOptions has many fields most are optional. We'll focus on the required options for now.
import { PublicClient } from 'viem';
import { ShieldedAccount } from '@zkfi-tech/account';
// Only showing required fields, skipping any optional fields for now
type CoreOptions = {
chainId: number;
account: ShieldedAccount;
rpc: PublicClient | string;
explorerApi: string;
}chainIdThe target chain on which you want to utilize the deployed instance of zkFi.
accountIt is the shielded account of the user who wants to perform private transactions of enquire about its balance or transaction history. AShieldedAccountcan be simply generated from a random seed. A seed is a randombigintnumber generated from a secure entropy source. You can generate the account by:const account = ShieldedAccount.generate(seed)Now you can pass the account to theCoreOption.rpcRPC URL of the provided chain or the viemPublicClient.explorerApiAPI URL of block explorer. You must append the API key of the block explorer in the API URL itself. For example, Optimism Sepolia's base API URL ishttps://api-sepolia-optimistic.etherscan.io/api. But, when including inCoreOptions, you must include theapikeyparameter. That is, API URL that you must pass is:https://api-sepolia-optimistic.etherscan.io/api?apikey=<YOUR_API_KEY>
After configuring options simply create an SDK instance as:
import {Core, CoreOptions} from '@zkfi-tech/core';
const opts: CoreOptions = {
// set options here
}
const zkfi = new Core(opts);The SDK instance (zkfi) above is ready to be utilized now. Next, let's see how to craft a shielded/private transaction i.e a ZTransaction instance.
Last updated