▶️Initializing SDK

Core Options

The SDK can be initialized with the given CoreOptions.

import { Hex } from 'viem';

type CoreOptions = {
  chainId: number;
  account: ShieldedAccount;
  rpc: PublicClient | string;
  explorerApi: string;
  contracts?: CoreContracts;
  circuits?: SDKCircuits;
  services?: {
    eventFetcher: IEventFetcher;
    addressResolver: IAddressResolver;
    treeSource: ITreeSource;
    notesSource: INotesSource;
  }
}
  • chainId: The chain ID of the instance of veilnyx where transactions will be sent.

  • account: The Account of the user, which will be used to sign and decrypt transactions.

  • rpc: RPC URL of the given chainId.

  • contracts: The various veilnyx contract addresses on the given chain.

  • circuits: Paths to ZK circuit artefacts.

  • snarkJsThe SDK requires snarkjsarrow-up-right for the purpose of proving a transaction. Depending on where you are utilizing the SDK, you need to install snarkjsarrow-up-right in your project before you start proving the transaction.

    • For node, install it as a dependency: npm install snarkjs and include it in CoreOptions.

    • For the browser, simply include it as a script using <script> a tag.

  • isTestnet : Boolean to specify if the chain is testnet.

  • servicesThe services needed for fetching external data are needed for the SDK to function. These services can be custom made e.g. for optimization, but default services are plugged in during SDK initialization.

Instantiation

You don't need to specify all the parameters in the options. Most parameters available are optional.

The only significant required parameter is the ShieldedAccount object corresponding to the shielded account of the user. To create ShieldedAccount You need a Viewer , andISigner of the connected wallet.

Then the SDK is simply initialized as:

Usage

The SDK instance, veilnyx Above is now ready to be used for various functionalities like:

  • getBalance() Returns the balance of various assets that are in the user's shielded account.

  • getHistory() Returns the decoded transaction history of the user.

  • createTransaction(req: TransactionRequest, opts: TransactionOptions) Creates a Transaction given request and options.

  • signTransaction(tx: Transaction) Sign the given transaction.

  • proveTransaction(tx: Transaction) Proves a given signed transaction by generating a ZK proof.

See the next section for the steps of crafting a transaction.

Last updated