▶️Initializing SDK
Core Options
The SDK can be initialized with the given CoreOptions
.
chainId
: The chain id of the instance of zkFi where transactions will be sent.account
: TheAccount
of the user which will be used to sign and decrypt transactions.rpc
: RPC url orf the givenchainId
.contracts
: The various zkFi contract addresses on the given chain.
circuits
: Paths to ZK circuit artifacts.snarkJs
: The SDK requires snarkjs for the purpose for proving a transaction. Depending on where you are utilizing the SDK, you need to install snarkjs in your project before you start proving the transaction.For node, install it as dependency:
npm install snarkjs
and include it inCoreOptions
.For the browser, simply include it as a script using
<script>
tag.
isTestnet
: Boolean to specify if the chain is testnet.services
: The services needed for fetching external data needed for 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. For creating ShieldedAccount
you need a Viewer
, andISigner
of the connected wallet.
Then SDK is simply initialized as:
Usage
The SDK instance, zkfi
above is now ready to be used for various functionalities like:
getBalance()
Returns the balance of various assets that is in user's shielded account.getHistory()
Returns decoded transaction history of the user.createTransaction(req: TransactionRequest, opts: TransactionOptions)
Creates aTransaction
given the request and options.signTransaction(tx: Transaction)
Signs the given transaction.proveTransaction(tx: Transaction)
Proves a given signed transaction by generating a ZK proof.
See the next section, for steps of crafting a transaction.
Last updated