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:

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

Instructions

  1. Instantiating the NotVault and Tokens classes:

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

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

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

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.

  1. Sending a confidential amount:

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.

  1. Retrieving a confidential amount:

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.

  1. Withdrawing an amount:

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:

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.

  1. View the private or confidential balance:

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

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

  1. View the public balance:

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

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

  1. View the locked outgoing balances:

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.

  1. View the locked incoming balances:

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.

Last updated