aftermath-ts-sdk - v3.3.3
    Preparing search index...

    Fetches current USD price information for Sui coin types.

    Each method sends a JSON POST request to the configured Aftermath price-info endpoint, which defaults to /api/price-info. Price values are JavaScript numbers expressed in USD per whole coin unit. The response also includes the service's 24-hour percentage change. Pass an AbortSignal to a method when the request must be cancellable. Coin types are passed to the endpoint without local validation. If neither network nor baseUrl is configured, a request rejects with an AftermathTransportError whose kind is "network".

    HTTP failures expose their status and optional retry delay on AftermathTransportError. Network, timeout, cancellation, and response decoding failures use the same error type with a corresponding kind.

    Hierarchy (View Summary)

    Index
    • Creates a price service with optional API host and authentication settings.

      Parameters

      • Optionalconfig: CallerConfig

        Optional HTTP caller configuration. Set network or baseUrl to select the API host. baseUrl takes precedence over network. Set accessToken to send a bearer token with each request.

      Returns Prices

      import { Aftermath } from "aftermath-ts-sdk";

      const sdk = await Aftermath.create({ network: "MAINNET" });
      const prices = sdk.Prices();
    config: CallerConfig

    The mutable configuration used for subsequent requests.

    • Fetches the current USD price for one coin type.

      This method fetches the coin's price information and returns only its price field. The returned number is USD per whole coin unit, not an on-chain smallest-unit amount.

      Pass abortSignal to cancel the underlying HTTP request.

      Parameters

      • inputs: { coin: string }

        The price request.

        • coin: string

          The Sui coin type to query, such as "0x2::sui::SUI".

      • OptionalabortSignal: AbortSignal

        Optional caller-owned signal forwarded to fetch.

      Returns Promise<number>

      The current price in USD per whole coin unit.

      AftermathTransportError when the request fails, is cancelled, or returns a response that cannot be decoded.

      import { Aftermath } from "aftermath-ts-sdk";

      const sdk = await Aftermath.create({ network: "MAINNET" });
      const prices = sdk.Prices();
      const suiPrice = await prices.getCoinPrice({ coin: "0x2::sui::SUI" });
      console.log("SUI price in USD:", suiPrice);
    • Fetches price information for one coin type.

      This method sends a one-element coins array to the multi-coin price endpoint and returns the first value in the response record. A successful response normally contains the requested coin's entry.

      Pass abortSignal to cancel the underlying HTTP request. A caller abort is reported as an AftermathTransportError with kind: "abort", unless the abort reason identifies a timeout.

      Parameters

      • inputs: { coin: string }

        The price request.

        • coin: string

          The Sui coin type to query, such as "0x2::sui::SUI".

      • OptionalabortSignal: AbortSignal

        Optional caller-owned signal forwarded to fetch.

      Returns Promise<CoinPriceInfo>

      The coin's price in USD per whole coin and its 24-hour percentage change.

      AftermathTransportError when the request fails, is cancelled, or returns a response that cannot be decoded.

      import { Aftermath } from "aftermath-ts-sdk";

      const sdk = await Aftermath.create({ network: "MAINNET" });
      const prices = sdk.Prices();

      const suiPriceInfo = await prices.getCoinPriceInfo({
      coin: "0x2::sui::SUI",
      });
      console.log(suiPriceInfo.price, suiPriceInfo.priceChange24HoursPercentage);
    • Fetches current USD prices for multiple coin types.

      This method fetches detailed price information and projects each response entry to its price field. The returned record keeps the response coin-type keys and contains USD per whole coin unit.

      Pass abortSignal to cancel the underlying HTTP request.

      Parameters

      • inputs: { coins: string[] }

        The price request.

        • coins: string[]

          The Sui coin types to query, such as ["0x2::sui::SUI"].

      • OptionalabortSignal: AbortSignal

        Optional caller-owned signal forwarded to fetch.

      Returns Promise<CoinsToPrice>

      A record mapping response coin types to current USD prices per whole coin unit.

      AftermathTransportError when the request fails, is cancelled, or returns a response that cannot be decoded.

      import { Aftermath } from "aftermath-ts-sdk";

      const sdk = await Aftermath.create({ network: "MAINNET" });
      const prices = sdk.Prices();
      const multiPrices = await prices.getCoinsToPrice({
      coins: ["0x2::sui::SUI"],
      });
      console.log(multiPrices["0x2::sui::SUI"]); // e.g. 1.23
    • Fetches price information for multiple coin types.

      This method sends inputs as a JSON POST body to the price-info endpoint, which defaults to /api/price-info. It returns the response record keyed by coin type. Each record value contains a USD price per whole coin and the service's 24-hour percentage change.

      Pass abortSignal to cancel the underlying HTTP request.

      Parameters

      • inputs: { coins: string[] }

        The price request.

        • coins: string[]

          The Sui coin types to query, such as ["0x2::sui::SUI"].

      • OptionalabortSignal: AbortSignal

        Optional caller-owned signal forwarded to fetch.

      Returns Promise<CoinsToPriceInfo>

      A record mapping the response coin types to their price information.

      AftermathTransportError when the request fails, is cancelled, or returns a response that cannot be decoded.

      import { Aftermath } from "aftermath-ts-sdk";

      const sdk = await Aftermath.create({ network: "MAINNET" });
      const prices = sdk.Prices();
      const info = await prices.getCoinsToPriceInfo({
      coins: ["0x2::sui::SUI"],
      });
      console.log(info);
    • Returns the canonical Aftermath API host for a Sui network.

      To target a custom or local host, pass baseUrl in CallerConfig to the constructor instead.

      Parameters

      • network: SuiNetwork

        The Sui network whose host to return.

      Returns string

      The network's HTTPS or local HTTP API host.