Skip to content

Examples: Get Mosaic info

Chun Lam edited this page Feb 21, 2024 · 5 revisions
import { MosaicHttp, MosaicId } from "tsjs-xpx-chain-sdk";

const API_URL = 'http://localhost:3000';

const mosaicHttp = new MosaicHttp(API_URL);

const getMosaicInformation = () => {
    const mosaicId = new MosaicId([
        481110499,
        231112638
    ]);

    mosaicHttp.getMosaic(mosaicId).subscribe({
        next: mosaicInfo => {
            console.log(mosaicInfo.mosaicId.toHex());
            console.log(mosaicInfo);
        }, 
        error: error => {
            console.error(error);
        }, 
        complete: () => {
            console.log('done.');
        }
    })
}


const getMosaicsInformationForSetOfMosaics = () => {
    const mosaicId1 = new MosaicId([
        481110499,
        231112638
    ]);
    const mosaicId2 = new MosaicId([
        519256100,
        642862634
    ]);
    mosaicHttp.getMosaics([mosaicId1, mosaicId2]).subscribe({
        next: mosaicInfo => {
            console.log(mosaicInfo);
        }, 
        error: error => {
            console.error(error);
        }, 
        complete: () => {
            console.log('done.');
        }
    })
}

const getMosaicNames = () => {
    const mosaicId1 = new MosaicId([
        481110499,
        231112638
    ]);
    const mosaicId2 = new MosaicId([
        519256100,
        642862634
    ]);
    mosaicHttp.getMosaicsNames([mosaicId1, mosaicId2]).subscribe({
        next: mosaicNames => {
            console.log(mosaicNames);
        }, 
        error: error => {
            console.error(error);
        }, 
        complete:() => {
            console.log('done.');
        }
    })
}

const getMosaicLevy = () => {
    const mosaicId1 = new MosaicId([
        481110499,
        231112638
    ]);
    mosaicHttp.getMosaicLevy(mosaicId1).subscribe({
        next: mosaicLevy => {
            console.log(mosaicLevy);
        }, 
        error: error => {
            console.error(error); // will return 404 if no levy found
        }, 
        complete: () => {
            console.log('done.');
        }
    })
}

const getMosaicRichlist = () => {
    const mosaicId1 = new MosaicId([
        481110499,
        231112638
    ]);
    mosaicHttp.getMosaicRichlist(mosaicId1).subscribe({
        next: richlistEntries => {
            console.log(richlistEntries);
        }, 
        error: error => {
            console.error(error);
        }, 
        complete: () => {
            console.log('done.');
        }
    })
}

getMosaicInformation();
getMosaicsInformationForSetOfMosaics();
getMosaicNames();
getMosaicLevy();
getMosaicRichlist();