# Initializing SDK

## Core Options

The SDK can be initialized with the given `CoreOptions`.&#x20;

{% code lineNumbers="true" %}

```typescript
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;
  }
}
```

{% endcode %}

* `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.&#x20;

{% code lineNumbers="true" %}

```typescript
type CorContracts = {
  pool: Hex;
  paymaster: Hex;
}
```

{% endcode %}

* `circuits`: Paths to ZK circuit artefacts.
* `snarkJs`The SDK requires [snarkjs](https://github.com/iden3/snarkjs) for the purpose of proving a transaction. Depending on where you are utilizing the SDK, you need to [install snarkjs](https://github.com/iden3/snarkjs?tab=readme-ov-file#using-node) 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.
* `services`The 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` , and`ISigner`  of the connected wallet.

```typescript
import { ShieldedAccount } from '@veilnyx-sdk/account';

const account = new Account(signer, viewer);
```

Then the SDK is simply initialized as:

```typescript
const veilnyx = new Core({
    chainId: <chain-id>,
    account,
    rpc: <rpc-url>
});
```

## 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.veilnyx.com/veilnyx-sdk/initializing-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
