This guide runs on testnet so your first swap costs nothing real. Get free testnet ALPH from the faucet:To go live, change
networkId to 'mainnet' and pick a token that has a mainnet pool. Mainnet swaps spend real funds.Requires Node.js 20+ (or Bun 1.0+).
1
Install
Start a new project as an ES module (the snippets use top-level Add
await):@alephium/web3-wallet too if you will sign from a backend with a private key.Put the snippets below in one index.ts file, in order, and run it with npx tsx index.ts (or bun index.ts).2
Load the SDK (read-only)
mainnet, testnet, and devnet ship inside the package.3
Read a CPMM pool and quote a swap
computeSwapAmount is a pure function: after the one getPoolState call, you can re-quote on every keystroke without touching the network.4
Attach a signer and swap
SignerProvider (for example from @alephium/web3-react) instead of a PrivateKeyWallet.5
Wait for confirmation
Next steps
TypeScript SDK
How the SDK is initialized, what each module does, and common pitfalls.
Swap on CLMM
Quote with a simulated liquidity curve, then execute with a price limit.
Amounts & slippage
bigint units, decimals, and how basis-point slippage is applied.
Stake ALPH
Mint xALPH and manage unstake requests.