#
NaiAsset objects
There are three asset types (token types) in Hive's layer 1 protocol: HIVE (liquid hive), VESTS (staked hive), and HBD (hive-backed dollars). All asset amounts are specified as fixed-point numbers to prevent rounding errors (these are especially problematic for financial calculations) . Hive and HBD use 3 digits of precision, VESTS are specified using 6 digits of precision.
Assets can be represented using two formats. The first is the deprecated string format. Here's an example of the deprecated format for 1 Hive token: "1.000 HIVE"
.
The second format is called Numeric Asset Identifier (NAI). NAI is the recommended format. With NAIs, asset types are specified using numbers rather than strings. NAIs were introduced to simplify supporting user-created asset types in the future.
Here's an example of an NAI asset for 1 hive token: {"amount":"1000","precision":3,"nai":"@@000000021"}
.
Important note
NAI amounts must be specified as integer values (no decimal point) and the precision is used to shift the decimal place appropriately. The NAI field is used to specify the asset type: 21 is HIVE, 37 is VESTS, and 13 is HBD. Precision is fixed for each asset type (3 or 6), so when creating NAI objects, only the integer quantity and type must be specified.
#
Creating NaiAsset objects for each asset type
import { createWaxFoundation } from '@hiveio/wax';
const waxApi = await createWaxFoundation();
// Convert the amount into `NaiAsset` for HIVE, HBD, and VESTS
const hiveAsset = waxApi.hiveSatoshis(1_000); // 1.000 HIVE
const hbdAsset = waxApi.hbdSatoshis(1_000); // 1.000 HBD
const vestsAsset = waxApi.vestsSatoshis(1_000000); // 1.000000 VESTS
console.log(`Hive Asset: ${JSON.stringify(hiveAsset)}`);
console.log(`HBD Asset: ${JSON.stringify(hbdAsset)}`);
console.log(`Vests Asset: ${JSON.stringify(vestsAsset)}`);