This page targets
@alephium/powfi-sdk@1.0.2. Pin exact versions in production and read the release notes before upgrading.Install
- Node.js 20+ or Bun 1.0+ (declared in
engines). - TypeScript 5.x. The package ships CommonJS (
lib/index.js), ESM (lib/index.mjs), and type declarations (lib/index.d.ts). - Native
bigintsupport. All on-chain amounts arebigint.
@alephium/web3 is a peer dependency (^3.0.3): install it yourself, as in the command above, so the SDK and your app share one copy. Pulled in automatically: @alephium/token-list, bignumber.js, decimal.js.
Initialize
Powfi.load is synchronous. It:
- Resolves the network from the built-in list (
mainnet,testnet,devnet) and appliesnetworkOverrides. - Creates a
NodeProviderand anExplorerProviderfor that network. - Instantiates every module and loads its contract IDs from the deployment files bundled in the package.
- Registers its providers as the global
@alephium/web3defaults (setCurrentProviders()), so generated contract helpers work right away.
The module facades
ModuleBase, which gives it access to the parent Powfi instance (scope: providers, signer, network) and a named logger. See Logging to turn on debug output.
Transaction results
Write methods sign and submit the transaction throughpowfi.signer. They return the @alephium/web3 result type of the underlying call:
powfi.nodeProvider.transactions.getTransactionsStatus({ txId }) until type === 'Confirmed' (see step 5 of the Quickstart).
There is no “build only” mode for most methods. The exception is CLMM add-liquidity:
getAddLiquidityParams returns the prepared call parameters, and addLiquidityFromParams executes them. For everything else, if you need an unsigned transaction, call the underlying script’s or contract’s .execute / .transact with a custom SignerProvider that captures the request instead of submitting it.Common pitfalls
1. Network mismatch
1. Network mismatch
Contract IDs come from the deployment file for
networkId. A mainnet signer with networkId: 'testnet' (or the reverse) builds transactions against contracts that don’t exist on the signer’s network. Always derive networkId from the same place as your wallet’s network.2. Token ordering
2. Token ordering
Pools are keyed by the lexicographically sorted pair (
token0 < token1). Getters such as getPoolId(tokenA, tokenB) sort for you. Reserves, prices, and sqrtPriceX96 are always expressed in sorted order (price = token1 per token0). Use sortTokens(a, b) whenever you map UI “base/quote” onto pool fields.3. CLMM swap uses token0/token1 for direction, not pool order
3. CLMM swap uses token0/token1 for direction, not pool order
In
ClmmSwapRequest, token0 is the input token and token1 is the output token. In ClmmSimulateSwapParams, the direction is set by zeroForOne instead. See Swap on CLMM.4. Stale state
4. Stale state
Quotes computed from a
CpmmPoolContractState or a ClmmSimulateSwapQuote go stale as soon as another trade lands. cpmm.swap re-fetches state before sending. For CLMM, re-run simulateSwap right before submitting, and always set a non-zero slippage.5. Slippage is in basis points, and applied differently per pool type
5. Slippage is in basis points, and applied differently per pool type
slippageBps: 50n means 0.5%. CPMM applies it to amounts (minimalAmount / maximalAmount). CLMM applies it to the price (a sqrtPriceLimitX96 bound). See Amounts & slippage.6. Groupless addresses
6. Groupless addresses
Alephium groupless addresses (no
:group suffix) are normalized to the protocol group internally for owner/recipient arguments. When you derive IDs yourself (for example clmm.getPositionId), pass the normalized form: normalizeAddress(address, powfi.clmm.getClmmConfig().groupIndex).7. CPMM price impact cap
7. CPMM price impact cap
cpmm.swap throws PriceImpactTooHighError when the quote’s price impact is ≥ 5% (MAX_PRICE_IMPACT). Split the trade or use swapTo (which skips the check) if you really mean it.Versioning policy
- Stable releases are published on npm as
@alephium/powfi-sdkunder thelatesttag. Release candidates use therctag. - Contract bindings (
clmm/,cpmm/,staking/) are regenerated from the contracts repository and bundled in the package. A contract upgrade that changes addresses or ABIs ships as a new SDK version. - Pin exact versions and read the release notes before upgrading.
Upgrading
- Read the release notes on GitHub.
- Bump
@alephium/powfi-sdkand make sure your@alephium/web3satisfies the SDK’s peer dependency (^3.0.3today) and that only one copy is installed (npm ls @alephium/web3). Duplicate@alephium/web3copies causeinstanceofand provider-registration bugs. - Run
tsc --noEmit. Most breaking changes surface as type errors. - Re-run your quote tests against testnet before switching mainnet traffic.
Getting help
- Bugs and feature requests: GitHub issues.
- Security issues: do not open a public issue. Contact the Powfi team privately.