Initial SetupInteracting with Fungible Token Program
7/11 tutorials
64%

Preparing for Network Interaction

Connecting to the API

With the help of the Gear-JS API library, start by connecting to the Vara testnet using the provided endpoint URL. This connection enables interaction with the network for various operations.

Setting Up Developer Accounts:

In this tutorial, developer accounts are used to facilitate transactions and other network activities. Such accounts are convenient for testing and development purposes.

Create a new account by generating a mnemonic and using the Keyring to create and manage it.

Additionally, create an account with predefined URI for Alice.

Warning: Developer accounts are intended for testing and development purposes only. Using developer accounts in production environments poses significant security risks, as these accounts are often publicly known and can be easily compromised. In a production environment, always use secure, user-managed accounts through a UI, allowing end-users to interact with the network using the wallet of their choice. This ensures better security and control over account management.

Defining Token Constants

Define a constant to represent the token, including its name, symbol, and decimal places. This constant will be used throughout the tutorial to reference the token's properties.

Additionally, calculate the token amount based on the specified decimals.

import { decodeAddress, GearApi } from '@gear-js/api';
import { Keyring } from '@polkadot/api';
import { mnemonicGenerate } from '@polkadot/util-crypto';

const VARA_TESTNET_ENDPOINT = 'wss://testnet.vara.network';
const api = await GearApi.create({ providerAddress: VARA_TESTNET_ENDPOINT });

const mnemonic = mnemonicGenerate();
const keyring = new Keyring({ type: 'sr25519' }).addFromMnemonic(mnemonic);
const aliceKeyring = new Keyring({ type: 'sr25519' }).addFromUri('//Alice');
const accountAddress = decodeAddress(keyring.address);
const aliceAccountAddress = decodeAddress(aliceKeyring.address);

const TOKEN = {
  NAME: 'Tutorial Token',
  SYMBOL: 'TT',
  DECIMALS: 12,
} as const;

const TOKENS_AMOUNT = 1 * 10 ** TOKEN.DECIMALS;