Balance and Transactions
The Logion network relies on the LGNT token. This section is about accessing you LGNT balance and transactions. It also shows how to transfer LGNTs.
State
note
An authenticated client is necessary for all balance-related operations.
The global state of the balances can be obtained (and later on, refreshed) with:
const balanceState = await authenticatedClient.balanceState();
const refreshedState = await balanceState.refresh();
caution
transfer
and refresh
do return a new state.
Always use the most recent state, and discard the former state.
In the example above, the var balanceState
must not be used any more as soon as refreshedState
is available.
Balance
You can get the current balance with:
const balance = balanceState.balances[0];
console.log(
"Balance :%s",
`${balance.balance.coefficient.toInteger()}.${balance.balance.coefficient.toFixedPrecisionDecimals(2)}${balance.balance.prefix.symbol}`
);
Transactions on the balance
You can get a list of transactions on the balance with:
const transactions = balanceState.transactions;
console.log("First transaction destination: %s", transactions[0].destination)
Transfer
You can transfer any amount (must be less than or equal to the balance, taking transaction fees into account) to another account:
import { Lgnt, ValidAccountId } from "@logion/node-api";
const destination = ValidAccountId.polkadot("vQx5kESPn8dWyX4KxMCKqUyCaWUwtui1isX6PVNcZh2Ghjitr"); // Alice
balanceState = balanceState.transfer({
amount: Lgnt.from(42n), // 42 LGNTs
destination,
signer,
});