- Home
- Developers
- TypeScript SDK
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.
npm install aftermath-ts-sdk @mysten/sui@^2import { 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()
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();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.
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);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}%`);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
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.
Versioned routes
Router, DCA, and limit-order builders call the versioned v1 API routes.
TransactionKind, not Transaction
Those builders return a base64-encoded TransactionKind rather than a fully built transaction.
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.
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.