> For the complete documentation index, see [llms.txt](https://docs.veilnyx.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.veilnyx.com/veilnyx-sdk/initializing-sdk.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
