Skip to content

Instantly share code, notes, and snippets.

@daoka
Created December 2, 2019 03:57
Show Gist options
  • Save daoka/2296ae2aac18152699c1b731950bf43a to your computer and use it in GitHub Desktop.
Save daoka/2296ae2aac18152699c1b731950bf43a to your computer and use it in GitHub Desktop.
Get account holds mosaics
import * as dotenv from 'dotenv';
import { MosaicHttp, Account, NetworkType, MosaicService, AccountHttp } from 'nem2-sdk';
import { mergeMap } from 'rxjs/operators';
dotenv.config();
const endpoint = process.env.API_ENDPOINT;
const accountHttp = new AccountHttp(endpoint);
const mosaicHttp = new MosaicHttp(endpoint);
const mosaicService = new MosaicService(accountHttp, mosaicHttp);
const account = Account.createFromPrivateKey(process.env.ACCOUNT_PRIVATE_KEY, NetworkType.MIJIN_TEST);
mosaicService.mosaicsAmountViewFromAddress(account.address).pipe(
mergeMap((_) => _),
).subscribe((x) => {
console.log('-- mosaic info --');
console.log(`mosaic id : ${x.mosaicInfo.id.toHex()}`);
console.log(`divisibility: ${x.mosaicInfo.divisibility}`);
console.log(`Absolute Amount: ${x.amount}`);
console.log(`Relative Amount: ${x.relativeAmount()}`);
}, (err) => {
console.log(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment