Check the number of asset units you have sent to an account.
// replace with signer public key
const signerPublicKey = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
// replace with recipient address
const recipientRawAddress = 'TB6Q5E-YACWBP-CXKGIL-I6XWCH-DRFLTB-KUK34I-YJQ';
const recipientAddress = Address.createFromRawAddress(recipientRawAddress);
// replace with mosaic id
const mosaicIdHex = '46BE9BC0626F9B1A';
// replace with mosaic divisibility
const divisibility = 6;
const mosaicId = new MosaicId(mosaicIdHex);
// replace with node endpoint
const nodeUrl = 'http://api-01.us-east-1.096x.symboldev.network:3000';
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
const transactionHttp = repositoryFactory.createTransactionRepository();
const searchCriteria = {
group: TransactionGroup.Confirmed,
signerPublicKey,
recipientAddress,
pageSize: 100,
pageNumber: 1,
type: [TransactionType.TRANSFER]};
transactionHttp
.search(searchCriteria)
.pipe(
map((_) => _.data),
// Process each transaction individually.
mergeMap((_) => _),
// Map transaction as transfer transaction.
map((_) => _ as TransferTransaction),
// Filter transactions containing a given mosaic
filter((_) => _.mosaics.length === 1 && _.mosaics[0].id.equals(mosaicId)),
// Transform absolute amount to relative amount.
map((_) => _.mosaics[0].amount.compact() / Math.pow(10, divisibility)),
// Add all amounts into an array.
toArray(),
// Sum all the amounts.
map((_) => _.reduce((a, b) => a + b, 0)),
)
.subscribe(
(total) => console.log('Total', mosaicId.toHex(),
'sent to account', recipientAddress.pretty(),
'is:', total),
(err) => console.error(err));
// replace with signer public key
const signerPublicKey = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
// replace with recipient address
const recipientRawAddress = 'TB6Q5E-YACWBP-CXKGIL-I6XWCH-DRFLTB-KUK34I-YJQ';
const recipientAddress = symbol_sdk_1.Address.createFromRawAddress(recipientRawAddress);
// replace with mosaic id
const mosaicIdHex = '46BE9BC0626F9B1A';
// replace with mosaic divisibility
const divisibility = 6;
const mosaicId = new symbol_sdk_1.MosaicId(mosaicIdHex);
// replace with node endpoint
const nodeUrl = 'http://api-01.us-east-1.096x.symboldev.network:3000';
const repositoryFactory = new symbol_sdk_1.RepositoryFactoryHttp(nodeUrl);
const transactionHttp = repositoryFactory.createTransactionRepository();
const searchCriteria = {
group: symbol_sdk_1.TransactionGroup.Confirmed,
signerPublicKey,
recipientAddress,
pageSize: 100,
pageNumber: 1,
type: [symbol_sdk_1.TransactionType.TRANSFER]
};
transactionHttp
.search(searchCriteria)
.pipe(operators_1.map((_) => _.data),
// Process each transaction individually.
operators_1.mergeMap((_) => _),
// Map transaction as transfer transaction.
operators_1.map((_) => _),
// Filter transactions containing a given mosaic
operators_1.filter((_) => _.mosaics.length === 1 && _.mosaics[0].id.equals(mosaicId)),
// Transform absolute amount to relative amount.
operators_1.map((_) => _.mosaics[0].amount.compact() / Math.pow(10, divisibility)),
// Add all amounts into an array.
operators_1.toArray(),
// Sum all the amounts.
operators_1.map((_) => _.reduce((a, b) => a + b, 0)))
.subscribe((total) => console.log('Total', mosaicId.toHex(), 'sent to account', recipientAddress.pretty(), 'is:', total), (err) => console.error(err));
If you want to check another mosaic different than the native currency, change mosaicId
and divisibility
for the target mosaic properties.
const mosaicId = new MosaicId('10293DE77C684F71');
const divisibility = 2;
Did you find what you were looking for? Give us your feedback.