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

    Provides balance and transaction-history queries for one Sui address.

    The methods send POST requests through the configured Aftermath HTTP API under /api/wallet by default. The apiEndpoint setting can change that prefix. Balance values are bigints in each coin's smallest unit. These methods do not accept an AbortSignal, so callers cannot cancel their requests through this class. 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".

    Hierarchy (View Summary)

    Index
    • Creates a wallet service for a specific Sui address.

      Parameters

      • address: string

        The Sui address string whose balances and transaction history to query. The address is passed to the API as walletAddress and is not validated or normalized by this constructor.

      • Optionalconfig: CallerConfig

        Optional HTTP caller configuration. Set network or baseUrl to select the API host. Set accessToken to send a bearer token.

      • Optionalapi: AftermathApi

        Optional low-level AftermathApi instance associated with the wallet. The current methods use the HTTP API configured by config.

      Returns Wallet

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

      const sdk = await Aftermath.create({ network: "MAINNET" });
      const wallet = sdk.Wallet(
      "0x00000000000000000000000000000000000000000000000000000000000000aa"
      );
    address: string

    The Sui address whose balances and history this instance queries.

    The optional low-level API provider associated with this wallet.

    config: CallerConfig

    The mutable configuration used for subsequent requests.

    • Fetches every coin balance held by this wallet address.

      This method sends { walletAddress: address } as a JSON POST body to the wallet balance endpoint. The response is a record keyed by the coin types returned by the API. Each value is a bigint in that coin's smallest unit.

      This method does not accept an AbortSignal.

      Returns Promise<CoinsToBalance>

      A record mapping returned coin types to balances in smallest units.

      AftermathTransportError when the HTTP request fails or its response cannot be decoded.

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

      const afSdk = await Aftermath.create({ network: "MAINNET" });
      const wallet = afSdk.Wallet(
      "0x00000000000000000000000000000000000000000000000000000000000000aa"
      );
      const allBalances = await wallet.getAllBalances();
      console.log(allBalances);
    • Fetches one coin balance for this wallet.

      This method sends the request { coins: [inputs.coin], walletAddress: address } to the wallet balance endpoint and returns the first balance in the response. The balance is a bigint in the coin's smallest unit, such as MIST for SUI.

      This method does not accept an AbortSignal.

      Parameters

      • inputs: { coin: string }

        The balance request.

        • coin: string

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

      Returns Promise<bigint>

      The requested coin balance in its smallest unit.

      AftermathTransportError when the HTTP request fails or its response cannot be decoded.

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

      const afSdk = await Aftermath.create({ network: "MAINNET" });

      const wallet = afSdk.Wallet(
      "0x00000000000000000000000000000000000000000000000000000000000000aa"
      );

      const suiBalance = await wallet.getBalance({ coin: "0x2::sui::SUI" });
      console.log("SUI balance in MIST:", suiBalance.toString());
    • Fetches balances for the requested coin types.

      This method sends { coins, walletAddress: address } as a JSON POST body to the wallet balance endpoint. The API returns one bigint balance per coin in the same order as inputs.coins, with each value in the coin's smallest unit.

      This method does not accept an AbortSignal.

      Parameters

      • inputs: { coins: string[] }

        The balance request.

        • coins: string[]

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

      Returns Promise<bigint[]>

      The balances in the request order. Each balance is a bigint in the corresponding coin's smallest unit.

      AftermathTransportError when the HTTP request fails or its response cannot be decoded.

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

      const afSdk = await Aftermath.create({ network: "MAINNET" });
      const wallet = afSdk.Wallet(
      "0x00000000000000000000000000000000000000000000000000000000000000aa"
      );
      const balances = await wallet.getBalances({
      coins: ["0x2::sui::SUI"],
      });
      console.log(balances); // e.g. [1000000000n]
    • Fetches a page of transactions sent from this wallet address.

      This method sends { ...inputs, walletAddress: address } as a JSON POST body to the wallet transaction-history endpoint. The cursor and limit values control pagination. The returned nextCursor is null when the response has no more transactions.

      This method does not accept an AbortSignal.

      Parameters

      Returns Promise<TransactionsWithCursor>

      The transaction page and its next transaction digest, if another page exists.

      AftermathTransportError when the HTTP request fails or its response cannot be decoded.

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

      const afSdk = await Aftermath.create({ network: "MAINNET" });
      const wallet = afSdk.Wallet(
      "0x00000000000000000000000000000000000000000000000000000000000000aa"
      );
      const txHistory = await wallet.getPastTransactions({ limit: 10 });
      console.log(txHistory.transactions, txHistory.nextCursor);
    • 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.