# 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: 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.notcentralised.com/sdk/tokens.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.
