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

# Tokens

The operations covered here include depositing an amount into the vault's private balance, sending a confidential amount, retrieving a confidential amount, and withdrawing an amount from the vault.

First, ensure you've imported the required libraries:

```typescript
import { NotVault, Tokens } from '@notcentralised/notvault-sdk';
```

### Instructions

1. **Instantiating the NotVault and Tokens classes:**

```typescript
const vault = new NotVault();
const tokens = new Tokens(vault);
```

This initializes the `NotVault` and `Tokens` classes, providing the groundwork for token operations.

2. **Depositing an amount into the vault's private balance:**

```typescript
await tokens.deposit('...Token Address...', BigInt(1000) /* token amount */ * BigInt(10 ** 18) /* token decimal places */);
```

This command deposits a specific amount into the vault's private balance. The amount is calculated as a product of the token amount and the token decimal places.

3. **Sending a confidential amount:**

```typescript
const idHash = await tokens.send(
    '...Token Address...',
    '... Email or Receipient address ...',
    BigInt(1000) /* token amount */ * BigInt(10 ** 18) /* token decimal places */
);
```

With this command, you can send a confidential amount to a recipient. The transaction id hash is stored for future reference.

4. **Retrieving a confidential amount:**

```typescript
await tokens.retreive(
    idHash,
    '...Token Address...',
    BigInt(1000) /* token amount */ * BigInt(10 ** 18) /* token decimal places */
);
```

This command allows for the retrieval of a confidential amount using the transaction id hash. This can be used in the event of a need for a transaction review or audit.

5. **Withdrawing an amount:**

```typescript
await tokens.withdraw(
    '...Token Address...',
    BigInt(1000) /* token amount */ * BigInt(10 ** 18) /* token decimal places */
);
```

This function permits you to withdraw a specified amount from the vault. This is useful for managing the flow of tokens and controlling the vault's balance.

Please refer to the original TypeScript code context for more granular detail on the parameters required for each function.

***

### Reading Token Balances

This section explains the steps to read various balances for a specific address using the NotVault SDK. This includes checking the private (confidential), public, locked outgoing, and locked incoming balances.

1. **Check the various balances a given address has in the vault:**

```typescript
const balance : Balance = await tokens.getBalance('...Token Address...');
```

This step fetches the `Balance` object for the given token address, which includes all different types of balances associated with the address.

2. **View the private or confidential balance:**

```typescript
console.log('Private or Confidential Balance', balance.privateBalance);
```

This logs the confidential balance, providing a view of the amount kept private in the vault.

3. **View the public balance:**

```typescript
console.log('Public Balance', balance.balance);
```

This logs the public balance associated with the token address, which indicates the publicly viewable amount.

4. **View the locked outgoing balances:**

```typescript
balance.lockedOut.forEach(element => {
    console.log('Locked Out', element);
});
```

This iterates over and logs each locked outgoing balance, providing visibility into amounts that are locked for outgoing transactions.

5. **View the locked incoming balances:**

```typescript
balance.lockedIn.forEach(element => {
    console.log('Locked In', element);
});
```

This iterates over and logs each locked incoming balance, which can provide insights into amounts locked for incoming transactions.


---

# 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 dynamically by asking a question.

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

```
GET https://docs.notcentralised.com/sdk/tokens.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
