Coin and Coins
A Coin
represents a single coin, which is a pair consisting of a denomination and an amount. Coins
represents a collection of Coin
objects, that many operators use to group tokens in one construct.
_9import { Coin, Coins } from '@terra-money/feather.js';_9_9const c = new Coin('uluna', 1500000); // 1.5 LUNA_9const c2 = new Coin('uluna', 3000000); // 3 LUNA_9c.add(c2); // 4.5 LUNA_9_9const cs = new Coins([c, c2]);_9const cs2 = new Coins({ uluna: 12002, uluna: 12399 });_9cs2.map((x) => console.log(`${x.denom}: ${x.amount}`));
Coin / Coins input with decimal input will automatically be converted to a decimal Coin.
_2const c = new Coin('uluna', 123.3); // a DecCoin_2const d = new Coin('uluna', '123.3'); // a DecCoin
Although it is convenient to represent the numbers through JavaScript's native Number
format, you should refrain from doing so.