var img = document.createElement('img'); img.src = "https://terradocs.matomo.cloud//piwik.php?idsite=1&rec=1&url=https://docs.terra.money" + location.pathname; img.style = "border:0"; img.alt = "tracker"; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(img,s);
Skip to main content

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.


_9
import { Coin, Coins } from '@terra-money/feather.js';
_9
_9
const c = new Coin('uluna', 1500000); // 1.5 LUNA
_9
const c2 = new Coin('uluna', 3000000); // 3 LUNA
_9
c.add(c2); // 4.5 LUNA
_9
_9
const cs = new Coins([c, c2]);
_9
const cs2 = new Coins({ uluna: 12002, uluna: 12399 });
_9
cs2.map((x) => console.log(`${x.denom}: ${x.amount}`));

Coin / Coins input with decimal input will automatically be converted to a decimal Coin.


_2
const c = new Coin('uluna', 123.3); // a DecCoin
_2
const 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.