Created
December 2, 2019 03:57
-
-
Save daoka/2296ae2aac18152699c1b731950bf43a to your computer and use it in GitHub Desktop.
Get account holds mosaics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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