Skip to content

TypeScript SDK

aftermath-ts-sdk

One provider, one set of typed accessors, and builders that hand your wallet a transaction to sign. The generated reference at ts-sdk.aftermath.finance covers every argument and return type.

Package
aftermath-ts-sdk
License
Apache-2.0
Module format
ESM only
Runtime dependency
date-fns
Peer dependency
@mysten/sui >=2.0.0 <3.0.0

Install

Two packages, no configuration.

The SDK talks to the public API, so the first call works with no credentials. Sui itself is a peer dependency — you bring the version your app already uses.

The package is ESM-only and sets type: module, with no CommonJS build. It compiles to ES2021; CI runs Node 22 and Bun 1.3.8. No engines field is declared, so npm enforces no minimum runtime.
install
npm install aftermath-ts-sdk @mysten/sui@^2
quickstart.ts
import { Aftermath } from "aftermath-ts-sdk";

const sdk = await Aftermath.create({ network: "MAINNET" });
const supportedCoins = await sdk.Router().getSupportedCoins();

console.log(supportedCoins);

Accessor surface

One provider, every protocol.

Aftermath.create returns a provider. Every protocol hangs off it as an accessor, and each accessor exposes reads plus transaction builders for that package.

  • Pools
  • Router
  • Staking
  • Farms
  • Perpetuals
  • NftAmm
  • SuiFrens
  • Faucet
  • GasPools
  • Coin
  • Sui
  • Auth
  • Dca
  • LimitOrders
  • Prices
  • Wallet
  • Multisig
  • Referrals
  • Rewards
  • UserData
  • DynamicGas

Marked accessors are provider-only: they exist on the instance but are not root exports of the package. Reach them through the provider, never through a named import.

Networks
MAINNET, TESTNET, DEVNET, LOCAL
Default network
MAINNET
Provider
Aftermath.create()
accessors.ts
import { Aftermath } from "aftermath-ts-sdk";

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

// Root exports exist for some packages, but every accessor is
// available from the provider — and for these, only from it.
const dca = sdk.Dca();
const limitOrders = sdk.LimitOrders();
const prices = sdk.Prices();
Named imports for Dca, LimitOrders, Prices, Wallet, Multisig, Referrals, Rewards, UserData, and DynamicGas do not resolve — they are not exported from the package root.

Reading state

Prices, yield, and pools.

Reads are plain async calls against the public API. These three are lifted from the SDK source and README.

coin-price.ts
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);
afsui-apy.ts
import { Aftermath } from "aftermath-ts-sdk";

const aftermath = await Aftermath.create({ network: "MAINNET" });
const staking = aftermath.Staking();
const apy = await staking.getApy();
console.log(`APY: ${apy * 100}%`);
pools.ts
const pools = afSdk.Pools();

const pool = await pools.getPool({ objectId: "0x<poolId>" });
const allPools = await pools.getAllPools();

Typed values

Units live in the type.

The types carry their units. Nothing is a bare number that silently means something else — read the type name before you scale a value.

Balance
bigint, in smallest units
Fields ending in Ms
Milliseconds
Slippage, Percentage
Decimal fraction — 0.01 is 1%
Apr, Apy
Decimal fraction — 0.01 is 1%
Bps
Integer basis points
stake.ts
const stakeTx = await sdk.Staking().getStakeTransaction({
  walletAddress,
  suiStakeAmount: 1_000_000_000n,
  validatorAddress,
});

1_000_000_000n is one SUI: a Balance is a bigint in the coin smallest units, and SUI has nine decimals. A Slippage of 0.01 is one percent, not one basis point.

Error model

One error type, five kinds.

Transport failures throw AftermathTransportError. Narrow an unknown catch with the isAftermathTransportError type guard, then branch on kind — the discriminant is one of five values.

  • http
  • network
  • abort
  • timeout
  • decode

AbortSignal is supported across initialization and read methods, so a component that unmounts, or a request that outlives its usefulness, can cancel the work instead of waiting it out.

Breaking change

4.0.0 moves gas to the caller.

Version 4.0.0 changed what transaction builders hand back. If you are upgrading from 3.x, this is the migration.

01

Versioned routes

Router, DCA, and limit-order builders call the versioned v1 API routes.

02

TransactionKind, not Transaction

Those builders return a base64-encoded TransactionKind rather than a fully built transaction.

03

Gas belongs to the caller

The returned kind carries no gas data. The wallet or signer that submits it owns gas budget, price, and payment.

A TransactionKind is not submittable on its own. Decode it, attach it to a transaction in your wallet flow, and let the signer set gas.

FAQ

Frequently asked questions

Read the full API surface.

Every accessor, argument, and return type is documented in the generated reference. The package itself is Apache-2.0 on npm and GitHub.