Skip to content

Examples: Get Harvester Info

Chun Lam edited this page Feb 21, 2024 · 2 revisions
import { 
    HarvesterHttp, NetworkType, HarvesterInfo, PublicAccount, PaginationQueryParams, Address
} from "tsjs-xpx-chain-sdk";

const API_URL = 'http://localhost:3000';
const NETWORK_TYPE = NetworkType.MIJIN_TEST;

const harvesterHttp = new HarvesterHttp(API_URL);

const getAccountHarvestingHarvesterInfo = () => {

    const address = Address.createFromRawAddress('SAFSPPRI4MBM3R7USYLJHUODAD5ZEK65YUP35NV6');

    return harvesterHttp.getAccountHarvestingHarvesterInfo(address).subscribe({
        next: harvestersInfo=>{
            // array of HarvesterInfo
            console.log(harvestersInfo);
        }, 
        error: error => {
            console.error(error);
        }, 
        complete: () => {
            console.log('done.');
        }
    });
}

const searchHarvesters = () => {

    // optional pagination query params filter
    return harvesterHttp.searchHarvesters().subscribe({
        next: harvestersSearch=>{
            // array of HarvesterInfo
            console.log(harvestersSearch.harvestersMetaInfo);
            console.log(harvestersSearch.pagination);
        }, 
        error: error => {
            console.error(error);
        }, 
        complete: () => {
            console.log('done.');
        }
    });
}

getAccountHarvestingHarvesterInfo();
searchHarvesters();