### Install Minter TypeScript SDK Source: https://github.com/counters/minter-typescript-sdk/blob/main/docs/README.md Install the SDK using yarn or npm. Specify the GitHub repository for direct installation or use the package name for the latest version. ```shell yarn add minter-typescript-sdk@github:counters/minter-typescript-sdk ``` ```shell yarn add minter-typescript-sdk ``` ```shell npm install counters/minter-typescript-sdk ``` ```shell npm install minter-typescript-sdk ``` -------------------------------- ### Install Minter TypeScript SDK Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Install the SDK using npm, yarn, or directly from the GitHub repository. ```shell # npm npm install minter-typescript-sdk # yarn yarn add minter-typescript-sdk # from GitHub yarn add minter-typescript-sdk@github:counters/minter-typescript-sdk ``` -------------------------------- ### Get Best Trade Information using gRPC Source: https://github.com/counters/minter-typescript-sdk/blob/main/docs/README.md Calculate the best trade route for a given amount and coin pair using getBestTradeGrpc. Specify the trade type (INPUT or OUTPUT). ```typescript import {BestTradeRequest} from "minter-typescript-sdk/lib/proto/resources_pb"; const bestTrade = await minterApi.getBestTradeGrpc(3757, 100.0, 1902, BestTradeRequest.Type.INPUT) console.info(bestTrade.toObject()); // { pathList: [ 3757, 1902 ], result: '7929802038004399105' } ``` -------------------------------- ### Get Coin Information using gRPC Source: https://github.com/counters/minter-typescript-sdk/blob/main/docs/README.md Retrieve information about a specific coin using the getCoinInfoGrpc method. The coin symbol is provided as a string argument. ```typescript const coinInfo = await minterApi.getCoinInfoGrpc("COUNTER"); console.info(coinInfo.toObject()); ``` -------------------------------- ### Initialize Minter API with gRPC Transport Source: https://github.com/counters/minter-typescript-sdk/blob/main/docs/README.md Demonstrates how to initialize the MinterApi instance using gRPC transport options. ```APIDOC ## Initialize Minter API with gRPC Transport ### Description Initialize the MinterApi with gRPC transport options. ### Method `new MinterApi(grpcOptions)` ### Parameters #### Request Body - **grpcOptions** (GrpcOptions) - Required - Configuration for gRPC transport. - **hostname** (string) - Required - The hostname of the gRPC server. - **port** (number) - Required - The port of the gRPC server. - **deadline** (number) - Required - The deadline for gRPC requests in milliseconds. - **useTransportSecurity** (boolean) - Required - Whether to use transport security. ### Request Example ```typescript import MinterApi, {GrpcOptions} from "minter-typescript-sdk"; const grpcOptions: GrpcOptions = { hostname: 'minter-api', port: 8842, deadline: 2500, useTransportSecurity: false }; const minterApi = new MinterApi(grpcOptions); ``` ``` -------------------------------- ### Initialize Minter API with HTTP/HTTPS Transport Source: https://github.com/counters/minter-typescript-sdk/blob/main/docs/README.md Demonstrates how to initialize the MinterApi instance using HTTP/HTTPS transport options. ```APIDOC ## Initialize Minter API with HTTP/HTTPS Transport ### Description Initialize the MinterApi with HTTP/HTTPS transport options. ### Method `new MinterApi(null, httpOptions)` ### Parameters #### Request Body - **httpOptions** (HttpOptions) - Required - Configuration for HTTP/HTTPS transport. - **raw** (string) - Required - The base URL for the Minter API. - **timeout** (number | null) - Optional - Request timeout in milliseconds. - **headers** (object | null) - Optional - Custom headers for requests. ### Request Example ```typescript import MinterApi, {HttpOptions} from "minter-typescript-sdk"; const httpOptions: HttpOptions = { raw: 'http://minter-api:8843/v2/', timeout: null, headers: null }; const minterApi = new MinterApi(null, httpOptions); ``` ``` -------------------------------- ### Browser Entry Point for Minter SDK Source: https://context7.com/counters/minter-typescript-sdk/llms.txt For browser environments, import from the dedicated browser entry point which excludes gRPC dependencies and allows direct initialization with HttpOptions. ```typescript import MinterApi, { HttpOptions } from "minter-typescript-sdk/lib/browser"; const httpOptions: HttpOptions = { raw: "https://minter-api.example.com/v2/", timeout: null, headers: null }; const api = new MinterApi(httpOptions); // browser: constructor takes HttpOptions directly ``` -------------------------------- ### Initialize MinterApi with gRPC or HTTP Transport Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Initialize the MinterApi facade with either gRPC or HTTP transport options. gRPC is Node.js only, while HTTP works in both Node.js and browsers. ```typescript import MinterApi, { GrpcOptions, HttpOptions } from "minter-typescript-sdk"; // gRPC transport (Node.js only) const grpcOptions: GrpcOptions = { hostname: "minter-api", port: 8842, deadline: 2500, // ms per-call timeout; null = no timeout useTransportSecurity: false }; const grpcApi = new MinterApi(grpcOptions); // HTTP transport (Node.js and browser) const httpOptions: HttpOptions = { raw: "http://minter-api:8843/v2/", timeout: null, headers: null }; const httpApi = new MinterApi(null, httpOptions); ``` -------------------------------- ### MinterApi - Unified API Client Source: https://context7.com/counters/minter-typescript-sdk/llms.txt The `MinterApi` class serves as the primary entry point for interacting with the Minter API. It supports both gRPC and HTTP transport layers, configurable via constructor options. ```APIDOC ## MinterApi ### Description `MinterApi` is the primary entry point for the SDK. It routes calls through either gRPC or HTTP transport based on the provided options. ### Constructor `new MinterApi(grpcOptions?: GrpcOptions, httpOptions?: HttpOptions)` - `grpcOptions`: Configuration for gRPC transport (Node.js only). - `httpOptions`: Configuration for HTTP transport (Node.js and browser). Exactly one of `grpcOptions` or `httpOptions` must be provided. ### Example (gRPC) ```typescript import MinterApi, { GrpcOptions } from "minter-typescript-sdk"; const grpcOptions: GrpcOptions = { hostname: "minter-api", port: 8842, deadline: 2500, // ms per-call timeout; null = no timeout useTransportSecurity: false }; const grpcApi = new MinterApi(grpcOptions); ``` ### Example (HTTP) ```typescript import MinterApi, { HttpOptions } from "minter-typescript-sdk"; const httpOptions: HttpOptions = { raw: "http://minter-api:8843/v2/", timeout: null, headers: null }; const httpApi = new MinterApi(null, httpOptions); ``` ``` -------------------------------- ### Query Wallet Balance with getAddressGrpc Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Retrieves wallet details including balances, delegated assets, transaction count, and multisig configuration. Use `delegated: true` to include delegated balances. ```typescript import MinterApi, { HttpOptions } from "minter-typescript-sdk"; const api = new MinterApi(null, { raw: "http://minter-api:8843/v2/", timeout: null, headers: null }); // Without delegated balances const result = await api.getAddressGrpc("Mx1234567890abcdef1234567890abcdef12345678"); result.balance.forEach(b => { console.info(b.coin?.symbol, b.value, b.bipValue); }); console.info("TX count:", result.transactionCount); // With delegated balances included const withDelegated = await api.getAddressGrpc( "Mx1234567890abcdef1234567890abcdef12345678", /* delegated */ true, /* height */ null, /* deadline */ 2000 ); withDelegated.delegated.forEach(d => { console.info(d.coin?.symbol, d.value, d.delegateBipValue); }); // Multisig wallet info if (withDelegated.multisig) { console.info("Threshold:", withDelegated.multisig.threshold); console.info("Addresses:", withDelegated.multisig.addresses); } ``` -------------------------------- ### Initialize Minter API with gRPC Transport Source: https://github.com/counters/minter-typescript-sdk/blob/main/docs/README.md Initialize the Minter API client using gRPC transport. Configure options such as hostname, port, deadline, and transport security. ```typescript import MinterApi, {GrpcOptions} from "minter-typescript-sdk"; const grpcOptions: GrpcOptions = { hostname: 'minter-api', port: 8842, deadline: 2500, useTransportSecurity: false }; const minterApi = new MinterApi(grpcOptions); ``` -------------------------------- ### Query Coin by Request Object with getCoinInfoByRequest Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Query coin information by providing a pre-built `CoinInfoRequest` Protobuf object. This is useful for programmatically composing requests using the `Params` helper. ```typescript import MinterApi, { Params, GrpcOptions } from "minter-typescript-sdk"; const params = new Params(); const request = params.requestCoinInfo("HUB", /* height */ 4800000); const api = new MinterApi( { hostname: "minter-api", port: 8842, deadline: 2500, useTransportSecurity: false } ); const coin = await api.getCoinInfoByRequest(request); console.info(coin.id); // numeric coin ID console.info(coin.symbol); // "HUB" ``` -------------------------------- ### Find Best Swap Path with getBestTradeGrpc Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Calculates the optimal multi-hop swap route between two coins. Specify `type` as `BestTradeRequest_Type.input` or `BestTradeRequest_Type.output` to indicate if the `amount` is the input or desired output. Returns the coin ID path and the resulting amount in PIP. ```typescript import MinterApi, { GrpcOptions } from "minter-typescript-sdk"; import { BestTradeRequest_Type } from "minter-typescript-sdk/lib/grpc"; import ConvertAmount from "minter-typescript-sdk/lib/utils/ConvertAmount"; const api = new MinterApi( { hostname: "minter-api", port: 8842, deadline: 2500, useTransportSecurity: false } ); const convert = new ConvertAmount(); // Best route: sell 100 COUNTER (id=3757) to get BIP (id=0), INPUT mode const trade = await api.getBestTradeGrpc( 3757, // sell_coin: COUNTER 100.0, // amount: 100 COUNTER (BIP units, converted to PIP internally) 0, // buy_coin: BIP (id=0) BestTradeRequest_Type.input, // type: amount is the input null, // max_depth: default null, // height: current null // deadline: default ); console.info("Path:", trade.path); // e.g. [3757, 1902, 0] console.info("Result (PIP):", trade.result); // raw PIP string console.info("Result (BIP):", convert.toBip(trade.result!)); // human-readable // OUTPUT mode: how much to sell to receive exactly 1 BIP const outTrade = await api.getBestTradeGrpc( 1902, 1.0, 0, BestTradeRequest_Type.output, // amount is the desired output ); console.info("Path:", outTrade.path); console.info("Must sell (PIP):", outTrade.result); ``` -------------------------------- ### ConvertAmount Utility Source: https://github.com/counters/minter-typescript-sdk/blob/main/docs/README.md Provides utility functions for converting amounts between BIP and PIP. ```APIDOC ## ConvertAmount Utility ### Description Provides utility functions for converting amounts between BIP and PIP. ### Methods #### toBip Converts a PIP amount to BIP. - **amount** (string) - Required - The PIP amount to convert. - **Returns** (string) - The converted BIP amount. #### toPip Converts a BIP amount to PIP. - **amount** (number) - Required - The BIP amount to convert. - **Returns** (string) - The converted PIP amount. ### Request Example ```typescript const convertAmount = new ConvertAmount(); console.info(convertAmount.toBip("1000000000000000000")); // 1.0 console.info(convertAmount.toPip(1.0)); // 1000000000000000000 ``` ``` -------------------------------- ### getBestTradeGrpc Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Calculates the most efficient multi-hop swap route between two coins, specifying whether the provided amount is the input or desired output. ```APIDOC ## getBestTradeGrpc — Find Best Swap Path Calculates the optimal multi-hop swap route between two coins. The `type` parameter specifies whether `amount` is the input (`BestTradeRequest_Type.input`) or desired output (`BestTradeRequest_Type.output`). Returns the coin ID path and the resulting amount in PIP. ```typescript import MinterApi, { GrpcOptions } from "minter-typescript-sdk"; import { BestTradeRequest_Type } from "minter-typescript-sdk/lib/grpc"; import ConvertAmount from "minter-typescript-sdk/lib/utils/ConvertAmount"; const api = new MinterApi( { hostname: "minter-api", port: 8842, deadline: 2500, useTransportSecurity: false } ); const convert = new ConvertAmount(); // Best route: sell 100 COUNTER (id=3757) to get BIP (id=0), INPUT mode const trade = await api.getBestTradeGrpc( 3757, // sell_coin: COUNTER 100.0, // amount: 100 COUNTER (BIP units, converted to PIP internally) 0, // buy_coin: BIP (id=0) BestTradeRequest_Type.input, // type: amount is the input null, // max_depth: default null, // height: current null // deadline: default ); console.info("Path:", trade.path); // e.g. [3757, 1902, 0] console.info("Result (PIP):", trade.result); // raw PIP string console.info("Result (BIP):", convert.toBip(trade.result!)); // human-readable // OUTPUT mode: how much to sell to receive exactly 1 BIP const outTrade = await api.getBestTradeGrpc( 1902, 1.0, 0, BestTradeRequest_Type.output, // amount is the desired output ); console.info("Path:", outTrade.path); console.info("Must sell (PIP):", outTrade.result); ``` ``` -------------------------------- ### Initialize Minter API with HTTP/HTTPS Transport Source: https://github.com/counters/minter-typescript-sdk/blob/main/docs/README.md Initialize the Minter API client using HTTP/HTTPS transport. Configure options like raw API endpoint, timeout, and headers. ```typescript import MinterApi, {HttpOptions} from "minter-typescript-sdk"; const httpOptions: HttpOptions = { raw: 'http://minter-api:8843/v2/', timeout: null, headers: null }; const minterApi = new MinterApi(null, httpOptions); ``` -------------------------------- ### getBestTradeGrpc Source: https://github.com/counters/minter-typescript-sdk/blob/main/docs/README.md Calculates the best trade route for a given amount and coin pair using gRPC. ```APIDOC ## getBestTradeGrpc ### Description Calculates the best trade route for a given amount and coin pair using gRPC. ### Method `minterApi.getBestTradeGrpc(sellCoinId, sellAmount, buyCoinId, type, maxDepth?, height?, deadline?)` ### Parameters #### Path Parameters - **sellCoinId** (number) - Required - The ID of the coin to sell. - **sellAmount** (number) - Required - The amount of the coin to sell. - **buyCoinId** (number) - Required - The ID of the coin to buy. - **type** (BestTradeRequest.Type) - Required - The type of trade (INPUT or OUTPUT). - **maxDepth** (number | null) - Optional - The maximum depth for the trade route. - **height** (number | null) - Optional - The block height to consider for the trade. - **deadline** (number | null) - Optional - The deadline for the trade in milliseconds. ### Request Example ```typescript import {BestTradeRequest} from "minter-typescript-sdk/lib/proto/resources_pb"; const bestTrade = await minterApi.getBestTradeGrpc(3757, 100.0, 1902, BestTradeRequest.Type.INPUT) console.info(bestTrade.toObject()); // { pathList: [ 3757, 1902 ], result: '7929802038004399105' } ``` ``` -------------------------------- ### getCoinInfoByRequest - Query Coin by Request Object Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Accepts a pre-built `CoinInfoRequest` Protobuf object, which is useful for composing requests programmatically using the `Params` helper. ```APIDOC ## getCoinInfoByRequest ### Description Accepts a pre-built `CoinInfoRequest` Protobuf object, useful for composing requests programmatically via the `Params` helper. ### Method Signature `getCoinInfoByRequest(request: CoinInfoRequest): Promise` ### Parameters - **request** (CoinInfoRequest) - Required - A Protobuf object representing the coin info request. ### Request Example ```typescript import MinterApi, { Params, GrpcOptions } from "minter-typescript-sdk"; const params = new Params(); const request = params.requestCoinInfo("HUB", /* height */ 4800000); const api = new MinterApi( { hostname: "minter-api", port: 8842, deadline: 2500, useTransportSecurity: false } ); const coin = await api.getCoinInfoByRequest(request); console.info(coin.id); // numeric coin ID console.info(coin.symbol); // "HUB" ``` ### Response #### Success Response (CoinInfoResponse) - **id** (number) - The unique identifier of the coin. - **symbol** (string) - The ticker symbol of the coin. ``` -------------------------------- ### Convert Amount Utility Source: https://github.com/counters/minter-typescript-sdk/blob/main/docs/README.md Utilize the ConvertAmount class to convert between BIP and PIP units. Use toBip for converting from PIP to BIP and toPip for the reverse conversion. ```typescript const convertAmount = new ConvertAmount(); console.info(convertAmount.toBip("1000000000000000000")); // 1.0 console.info(convertAmount.toPip(1.0)); // 1000000000000000000 ``` -------------------------------- ### Direct gRPC Transport with MinterGrpcApi Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Use MinterGrpcApi for direct gRPC calls with pre-built Protobuf requests. Ensure correct GrpcOptions are provided for connection. ```typescript import { MinterGrpcApi, GrpcOptions, Params } from "minter-typescript-sdk"; const options: GrpcOptions = { hostname: "minter-api", port: 8842, deadline: 2500, useTransportSecurity: false }; const grpcApi = new MinterGrpcApi(options); const params = new Params(); // Coin info via gRPC with explicit request object const request = params.requestCoinInfo("COUNTER", null); const coin = await grpcApi.getCoinInfoGrpc(request, /* deadline */ 1000); console.info(coin.id, coin.symbol); // Estimate coin sell via gRPC const sellRequest = params.requestEstimateCoinSell(3757, "100000000000000000000", 0, null, null, null, null); const sellResult = await grpcApi.estimateCoinSellGrpc(sellRequest); console.info(sellResult.willGet, sellResult.swapFrom); ``` -------------------------------- ### Convert Between BIP and PIP Units Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Utility for converting between the human-readable BIP unit and the raw PIP unit used by the blockchain. Uses `big.js` for precise calculations. Returns a string for PIP conversions to maintain precision. ```typescript import { ConvertAmount } from "minter-typescript-sdk"; const convert = new ConvertAmount(); // BIP → PIP (returns string to preserve precision) console.info(convert.toPip(1.0)); // "1000000000000000000" console.info(convert.toPip(0.5)); // "500000000000000000" console.info(convert.toPip(1234.567)); // "1234567000000000000" // PIP → BIP (returns number) console.info(convert.toBip("1000000000000000000")); // 1 console.info(convert.toBip("500000000000000000")); // 0.5 console.info(convert.toBip("7929802038004399105")); // ~7.929... // Practical example: display a raw API result in BIP const trade = await api.getBestTradeGrpc(3757, 100.0, 1902, BestTradeRequest_Type.input); const humanReadable = convert.toBip(trade.result!); console.info(`You will receive: ${humanReadable} HUB`); ``` -------------------------------- ### Params: Request Builder for Protobuf Objects Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Use the Params class to construct typed Protobuf request objects for gRPC calls. Supports various request types including coin info, address details, and trade estimations. ```typescript import { Params } from "minter-typescript-sdk"; import { BestTradeRequest_Type, CandidatesRequest_CandidateStatus } from "minter-typescript-sdk/lib/grpc"; const params = new Params(); // Build a CoinInfoRequest const coinReq = params.requestCoinInfo("BIP", /* height */ null); // Build an AddressRequest with delegated balances at a specific height const addrReq = params.requestAddress("Mx1234567890abcdef1234567890abcdef12345678", true, 5000000); // Build an EstimateCoinSellRequest (valueToSell must be in PIP) const sellReq = params.requestEstimateCoinSell( 1902, // coinToSell: HUB "1000000000000000000", // valueToSell: 1 HUB in PIP 0, // coinToBuy: BIP null, // coin_id_commission null, // swap_from null, // route null // height ); // Build a BestTradeRequest const tradeReq = params.requestBestTrade( 3757, // sell_coin "100000000000000000000", // amount in PIP 1902, // buy_coin BestTradeRequest_Type.input, // type null, // max_depth null // height ); // Build a CandidatesRequest const candidatesReq = params.requestCandidates( true, // includeStakes false, // notShowStakes CandidatesRequest_CandidateStatus.validator, // status null // height ); ``` -------------------------------- ### Import Minter API for Browser Source: https://github.com/counters/minter-typescript-sdk/blob/main/docs/README.md Import the Minter API specifically for browser environments. This ensures compatibility with browser-specific modules. ```typescript import MinterApi, {HttpOptions} from "minter-typescript-sdk/lib/browser"; ``` -------------------------------- ### getCoinInfoGrpc Source: https://github.com/counters/minter-typescript-sdk/blob/main/docs/README.md Retrieves information about a specific coin using gRPC. ```APIDOC ## getCoinInfoGrpc ### Description Retrieves information about a specific coin using gRPC. ### Method `minterApi.getCoinInfoGrpc(coinSymbol)` ### Parameters #### Path Parameters - **coinSymbol** (string) - Required - The symbol of the coin to retrieve information for. ### Request Example ```typescript const coinInfo = await minterApi.getCoinInfoGrpc("COUNTER"); console.info(coinInfo.toObject()); ``` ``` -------------------------------- ### Direct HTTP API Calls with MinterHttpApi Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Low-level HTTP client for the Minter v2 REST API, useful when the `MinterApi` facade is insufficient. Supports fetching both raw JSON and typed Protobuf responses. ```typescript import { MinterHttpApi, HttpOptions } from "minter-typescript-sdk"; const options: HttpOptions = { raw: "http://minter-api:8843/v2/", timeout: null, headers: null }; const httpApi = new MinterHttpApi(options); // Get raw JSON (useful for debugging or custom parsing) const rawJson = await httpApi.getCoinInfoJson("BIP"); console.info(rawJson); // plain API JSON object // Get typed Protobuf response const typed = await httpApi.getCoinInfoGrpc("BIP"); console.info(typed.id, typed.symbol, typed.crr); // Estimate coin sell returning raw JSON const sellJson = await httpApi.estimateCoinSellJsonByRequest( new Params().requestEstimateCoinSell(1902, "1000000000000000000", 0, null, null, null, null) ); console.info(sellJson); // { will_get: "...", commission: "...", swap_from: "pool" } ``` -------------------------------- ### Query Coin Metadata with getCoinInfoGrpc Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Retrieve on-chain metadata for a coin using its ticker symbol. Optionally query at a specific block height or set a custom per-call deadline. ```typescript import MinterApi, { HttpOptions } from "minter-typescript-sdk"; const api = new MinterApi(null, { raw: "http://minter-api:8843/v2/", timeout: null, headers: null }); // Basic usage const coin = await api.getCoinInfoGrpc("ROBOT"); console.info(coin.symbol); // "ROBOT" console.info(coin.id); // e.g. 1902 console.info(coin.reserveBalance); // reserve in PIP (string) console.info(coin.mintable); // boolean // At a specific block height const coinAtBlock = await api.getCoinInfoGrpc("USDTE", 5000000); console.info(coinAtBlock.volume); // supply at block 5000000 // With a custom per-call deadline (ms) const coinWithDeadline = await api.getCoinInfoGrpc("BIP", null, 1000); ``` -------------------------------- ### getCandidatesGrpc — Query All Validator Candidates Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Returns the full list of validator candidates. Supports filtering by status and controlling whether stake data is included. ```APIDOC ## getCandidatesGrpc — Query All Validator Candidates ### Description Returns the full list of validator candidates. Supports filtering by status (`all`, `on`, `off`, `validator`) and controlling whether stake data is included. ### Method Signature `api.getCandidatesGrpc(includeStakes: boolean, notShowStakes: boolean, candidateStatus: CandidatesRequest_CandidateStatus, height: number | null, deadline: number | null): Promise` ### Parameters - **includeStakes** (boolean) - If true, includes stake details for each candidate. - **notShowStakes** (boolean) - If true, stake details will not be included in the response. (Note: This seems redundant with `includeStakes` based on examples, clarification might be needed). - **candidateStatus** (CandidatesRequest_CandidateStatus) - Filters candidates by status. Possible values: `all`, `on`, `off`, `validator`. - **height** (number | null) - The block height at which to query the data. If null, the latest block is used. - **deadline** (number | null) - The deadline for the gRPC request in milliseconds. ### Response - **candidates** (Array) - An array of candidate objects. - **id** (number) - The candidate's ID. - **status** (number) - The candidate's status (1=offline, 2=online). - **totalStake** (string) - The total stake amount. - **commission** (number) - The commission rate in percent. - **validator** (boolean) - Indicates if the candidate is currently a validator. - **rewardAddress** (string) - The reward address. - **stakes** (Array) - An array of stake objects (if `includeStakes` is true and `notShowStakes` is false). ``` -------------------------------- ### MinterGrpcApi - Direct gRPC Transport Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Provides a low-level gRPC client for direct interaction with the Minter API using pre-built Protobuf request objects. This is useful for advanced use cases or when needing more control than the higher-level MinterApi offers. ```APIDOC ## MinterGrpcApi — Direct gRPC Transport Low-level gRPC client used internally by `MinterApi`. Can be used directly to call methods with pre-built Protobuf request objects. ```typescript import { MinterGrpcApi, GrpcOptions, Params } from "minter-typescript-sdk"; const options: GrpcOptions = { hostname: "minter-api", port: 8842, deadline: 2500, useTransportSecurity: false }; const grpcApi = new MinterGrpcApi(options); const params = new Params(); // Coin info via gRPC with explicit request object const request = params.requestCoinInfo("COUNTER", null); const coin = await grpcApi.getCoinInfoGrpc(request, /* deadline */ 1000); console.info(coin.id, coin.symbol); // Estimate coin sell via gRPC const sellRequest = params.requestEstimateCoinSell(3757, "100000000000000000000", 0, null, null, null, null); const sellResult = await grpcApi.estimateCoinSellGrpc(sellRequest); console.info(sellResult.willGet, sellResult.swapFrom); ``` ``` -------------------------------- ### Params - Request Builder Source: https://context7.com/counters/minter-typescript-sdk/llms.txt A helper class for constructing typed Protobuf request objects. These objects are used by the lower-level gRPC transport classes and are essential for making specific API calls. ```APIDOC ## Params — Request Builder Helper class for constructing typed Protobuf request objects. Used internally by `MinterApi` and available for direct use with the lower-level transport classes. ```typescript import { Params } from "minter-typescript-sdk"; import { BestTradeRequest_Type, CandidatesRequest_CandidateStatus } from "minter-typescript-sdk/lib/grpc"; const params = new Params(); // Build a CoinInfoRequest const coinReq = params.requestCoinInfo("BIP", /* height */ null); // Build an AddressRequest with delegated balances at a specific height const addrReq = params.requestAddress("Mx1234567890abcdef1234567890abcdef12345678", true, 5000000); // Build an EstimateCoinSellRequest (valueToSell must be in PIP) const sellReq = params.requestEstimateCoinSell( 1902, // coinToSell: HUB "1000000000000000000", // valueToSell: 1 HUB in PIP 0, // coinToBuy: BIP null, // coin_id_commission null, // swap_from null, // route null // height ); // Build a BestTradeRequest const tradeReq = params.requestBestTrade( 3757, // sell_coin "100000000000000000000", // amount in PIP 1902, // buy_coin BestTradeRequest_Type.input, // type null, // max_depth null // height ); // Build a CandidatesRequest const candidatesReq = params.requestCandidates( true, // includeStakes false, // notShowStakes CandidatesRequest_CandidateStatus.validator, // status null // height ); ``` ``` -------------------------------- ### getCandidateGrpc — Query Validator Candidate Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Fetches detailed information about a single validator candidate by its public key. Includes stakes, reward/owner/control addresses, commission, and status. ```APIDOC ## getCandidateGrpc — Query Validator Candidate ### Description Fetches detailed information about a single validator candidate by its public key, including stakes, reward/owner/control addresses, commission, and status. ### Method Signature `api.getCandidateGrpc(publicKey: string, notShowStakes: boolean, height: number | null, deadline: number | null): Promise` ### Parameters - **publicKey** (string) - The public key of the validator candidate. - **notShowStakes** (boolean) - If true, stake details will not be included in the response. - **height** (number | null) - The block height at which to query the data. If null, the latest block is used. - **deadline** (number | null) - The deadline for the gRPC request in milliseconds. ### Response - **id** (number) - The candidate's ID. - **status** (number) - The candidate's status (1=offline, 2=online). - **totalStake** (string) - The total stake amount. - **commission** (number) - The commission rate in percent. - **validator** (boolean) - Indicates if the candidate is currently a validator. - **rewardAddress** (string) - The reward address. - **stakes** (Array) - An array of stake objects (if `notShowStakes` is false). - **owner** (string) - The owner of the stake. - **coin** (Coin) - Information about the staked coin. - **id** (number) - The coin ID. - **symbol** (string) - The coin symbol. - **value** (string) - The stake amount. ``` -------------------------------- ### getAddressGrpc Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Retrieves comprehensive wallet information including balances, delegated assets, transaction count, and multisig configuration for a given Minter address. ```APIDOC ## getAddressGrpc — Query Wallet Balance Returns balances, delegated assets, total holdings, transaction count, and optional multisig configuration for a Minter wallet address. ```typescript import MinterApi, { HttpOptions } from "minter-typescript-sdk"; const api = new MinterApi(null, { raw: "http://minter-api:8843/v2/", timeout: null, headers: null }); // Without delegated balances const result = await api.getAddressGrpc("Mx1234567890abcdef1234567890abcdef12345678"); result.balance.forEach(b => { console.info(b.coin?.symbol, b.value, b.bipValue); }); console.info("TX count:", result.transactionCount); // With delegated balances included const withDelegated = await api.getAddressGrpc( "Mx1234567890abcdef1234567890abcdef12345678", /* delegated */ true, /* height */ null, /* deadline */ 2000 ); withDelegated.delegated.forEach(d => { console.info(d.coin?.symbol, d.value, d.delegateBipValue); }); // Multisig wallet info if (withDelegated.multisig) { console.info("Threshold:", withDelegated.multisig.threshold); console.info("Addresses:", withDelegated.multisig.addresses); } ``` ``` -------------------------------- ### Estimate Coin Sell Trade with estimateCoinSellGrpc Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Estimates the amount of `coinToBuy` received when selling `coinToSell`. Coin IDs are numeric. Supports routing through liquidity pools by specifying `swap_from` or `route`. The `valueToSell` is in human-readable BIP units. ```typescript import MinterApi, { GrpcOptions } from "minter-typescript-sdk"; import { SwapFrom } from "minter-typescript-sdk/lib/grpc"; const api = new MinterApi( { hostname: "minter-api", port: 8842, deadline: 2500, useTransportSecurity: false } ); // Sell 1 HUB (id=1902) for BIP (id=0) const estimate = await api.estimateCoinSellGrpc( 1902, // coinToSell: HUB 1.0, // valueToSell: 1 HUB (in BIP units) 0, // coinToBuy: BIP null, // coin_id_commission: use default null, // swap_from: auto (optimal) null, // route: no explicit route null, // height: current null // deadline: use global ); console.info("Will get (PIP):", estimate.willGet); console.info("Commission (PIP):", estimate.commission); console.info("Swap from:", estimate.swapFrom); // 0=bancor, 1=pool, 2=optimal // With explicit routing through intermediate coin const routedEstimate = await api.estimateCoinSellGrpc( 1902, // HUB 5.0, 0, // BIP null, null, [1993], // route via USDTE (id=1993) null, 1500 ); ``` -------------------------------- ### Error Handling Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Demonstrates how to handle errors when using both gRPC and HTTP transports. Promises are rejected with error objects on failure, providing details specific to the transport type. ```APIDOC ## Error Handling Both gRPC and HTTP transports reject Promises with error objects on failure. HTTP errors include the response body; gRPC errors include the status code and message. ```typescript import MinterApi, { HttpOptions } from "minter-typescript-sdk"; const api = new MinterApi(null, { raw: "http://minter-api:8843/v2/", timeout: null, headers: null }); // Wrap calls in try/catch try { const coin = await api.getCoinInfoGrpc("NONEXISTENT_COIN"); } catch (err) { // HTTP: err is the parsed JSON error body from the Minter node // gRPC: err contains { code, details, metadata } console.error("Error fetching coin info:", err); } // Promise .catch() style api.getBestTradeGrpc(3757, 100.0, 0, BestTradeRequest_Type.input) .then(result => console.info("Path:", result.path)) .catch(err => console.error("Trade failed:", err)); ``` ``` -------------------------------- ### ConvertSwapFrom - SwapFrom Enum Conversion Source: https://context7.com/counters/minter-typescript-sdk/llms.txt A utility class for converting between the `SwapFrom` enum values and their corresponding string representations used in HTTP API query parameters and JSON responses. ```APIDOC ## ConvertSwapFrom — SwapFrom Enum Conversion Utility for converting between `SwapFrom` enum values and the string names used by the HTTP API (`"bancor"`, `"pool"`, `"optimal"`). ```typescript import { ConvertSwapFrom } from "minter-typescript-sdk"; import { SwapFrom } from "minter-typescript-sdk/lib/grpc"; const converter = new ConvertSwapFrom(); // Enum → string (for HTTP query params) console.info(converter.getName(SwapFrom.bancor)); // "bancor" console.info(converter.getName(SwapFrom.pool)); // "pool" console.info(converter.getName(SwapFrom.optimal)); // "optimal" // String → enum (from HTTP JSON response) const swapFrom = converter.getSwapFrom("pool"); if (swapFrom !== null) { console.info(swapFrom === SwapFrom.pool); // true } ``` ``` -------------------------------- ### estimateCoinSellGrpc Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Estimates the amount of a target coin you will receive when selling a specified amount of another coin, with options for routing through liquidity pools. ```APIDOC ## estimateCoinSellGrpc — Estimate Coin Sell Trade Estimates how much of `coinToBuy` you will receive when selling a given amount of `coinToSell`. Coin IDs are numeric. The `valueToSell` is provided in human-readable BIP units (the SDK converts internally to PIP). Supports routing through liquidity pools (`swap_from`: `"bancor"`, `"pool"`, `"optimal"`). ```typescript import MinterApi, { GrpcOptions } from "minter-typescript-sdk"; import { SwapFrom } from "minter-typescript-sdk/lib/grpc"; const api = new MinterApi( { hostname: "minter-api", port: 8842, deadline: 2500, useTransportSecurity: false } ); // Sell 1 HUB (id=1902) for BIP (id=0) const estimate = await api.estimateCoinSellGrpc( 1902, // coinToSell: HUB 1.0, // valueToSell: 1 HUB (in BIP units) 0, // coinToBuy: BIP null, // coin_id_commission: use default null, // swap_from: auto (optimal) null, // route: no explicit route null, // height: current null // deadline: use global ); console.info("Will get (PIP):", estimate.willGet); console.info("Commission (PIP):", estimate.commission); console.info("Swap from:", estimate.swapFrom); // 0=bancor, 1=pool, 2=optimal // With explicit routing through intermediate coin const routedEstimate = await api.estimateCoinSellGrpc( 1902, // HUB 5.0, 0, // BIP null, null, [1993], // route via USDTE (id=1993) null, 1500 ); ``` ``` -------------------------------- ### Query All Validator Candidates Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Retrieves a list of all validator candidates. Supports filtering by status and controlling the inclusion of stake details. Use `includeStakes: false` for performance when stake data is not needed. ```typescript import MinterApi, { GrpcOptions } from "minter-typescript-sdk"; import { CandidatesRequest_CandidateStatus } from "minter-typescript-sdk/lib/grpc"; const api = new MinterApi( { hostname: "minter-api", port: 8842, deadline: 5000, useTransportSecurity: false } ); // All active validators with stakes const { candidates } = await api.getCandidatesGrpc( /* includeStakes */ true, /* notShowStakes */ false, /* candidateStatus */ CandidatesRequest_CandidateStatus.validator, /* height */ null, /* deadline */ 5000 ); console.info("Active validators:", candidates.length); candidates.forEach(c => { console.info(c.publicKey, "stake:", c.totalStake, "commission:", c.commission); }); // All candidates (no stake detail) for a lighter response const all = await api.getCandidatesGrpc(false, true, CandidatesRequest_CandidateStatus.all); console.info("Total candidates:", all.candidates.length); ``` -------------------------------- ### Error Handling with Minter SDK Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Handle errors from both gRPC and HTTP transports using try/catch blocks or Promise .catch() methods. gRPC errors include status code and message, while HTTP errors contain the parsed JSON response body. ```typescript import MinterApi, { HttpOptions } from "minter-typescript-sdk"; const api = new MinterApi(null, { raw: "http://minter-api:8843/v2/", timeout: null, headers: null }); // Wrap calls in try/catch try { const coin = await api.getCoinInfoGrpc("NONEXISTENT_COIN"); } catch (err) { // HTTP: err is the parsed JSON error body from the Minter node // gRPC: err contains { code, details, metadata } console.error("Error fetching coin info:", err); } // Promise .catch() style api.getBestTradeGrpc(3757, 100.0, 0, BestTradeRequest_Type.input) .then(result => console.info("Path:", result.path)) .catch(err => console.error("Trade failed:", err)); ``` -------------------------------- ### ConvertSwapFrom Enum Conversion Utility Source: https://context7.com/counters/minter-typescript-sdk/llms.txt Convert between SwapFrom enum values and their string representations for HTTP API usage. Handles both enum-to-string and string-to-enum conversions. ```typescript import { ConvertSwapFrom } from "minter-typescript-sdk"; import { SwapFrom } from "minter-typescript-sdk/lib/grpc"; const converter = new ConvertSwapFrom(); // Enum → string (for HTTP query params) console.info(converter.getName(SwapFrom.bancor)); // "bancor" console.info(converter.getName(SwapFrom.pool)); // "pool" console.info(converter.getName(SwapFrom.optimal)); // "optimal" // String → enum (from HTTP JSON response) const swapFrom = converter.getSwapFrom("pool"); if (swapFrom !== null) { console.info(swapFrom === SwapFrom.pool); // true } ```