> ## Documentation Index
> Fetch the complete documentation index at: https://docs.powfi.alephium.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Errors

> Typed SDK errors and the plain errors thrown by validation.

export const VersionBanner = ({network = 'mainnet', products = [], lang = 'en'}) => {
  const SDK_VERSION = '1.0.2';
  const ADDRESSES = {
    mainnet: {
      cpmm: {
        Router: 'ze15rnAwTyVCPnDhN7J8An3SvNeWBsZHAVMeBx1ehXeP',
        TokenPairFactory: '24CXRLvj1QiDH6riwr1EPERG7BcduHKZtktygbq97MfYb'
      },
      clmm: {
        PoolFactory: '24gqd4DMQXVzjm5QDAGxUtYupx3WM2PSu3vZUseuBCV9h',
        PositionManager: 'vFyKSqnJHS9MicrojBcLgztyRFqhS4hB349Ci3LJCELw'
      },
      staking: {
        XAlphToken: '225WevmFp5ZgzPsyVJTvyp2v2uyKrvp329HfrVmzffnWj',
        RewardFeeCollector: '22CE7vG6u64zjjsLZLxeJqQuPDydjPvbP9iG1d861j2G7'
      }
    },
    testnet: {
      cpmm: {
        Router: 'xaueT8kPMvpnaFJEfHv6CJLgqsSPpoNmHjF1QgTxoF9R',
        TokenPairFactory: '29hdd9b9Gp7oXuamwHKfUqBaRXP487HoeTcutS3RhZJEj'
      },
      clmm: {
        PoolFactory: 'z2QFT7qBQrfm8UwAYG3VHWoHs7B56ZDFNdSCcDu5j53m',
        PositionManager: '21p6egW8d6FEyVVuH17WqvHCARsCsD61GcBmeCr75XdGT'
      },
      staking: {
        XAlphToken: '23psDicimC5VdpM56wrgqgCzQzcyXWGCkQGSYWbtZAPRq',
        RewardFeeCollector: '29qQ1LPJ5uqawRviXLVDMeo19JUygRrNNTQy5RUBh817D'
      }
    }
  };
  const EXPLORERS = {
    mainnet: 'https://explorer.alephium.org/addresses/',
    testnet: 'https://testnet.alephium.org/addresses/'
  };
  const LABELS = {
    en: {
      sdk: 'SDK',
      network: 'Network',
      contracts: 'Contracts',
      all: 'All addresses',
      allNetworks: 'mainnet · testnet · devnet',
      devnet: 'Local deployment (addresses vary per devnet)'
    },
    zh: {
      sdk: 'SDK 版本',
      network: '网络',
      contracts: '合约',
      all: '全部地址',
      allNetworks: 'mainnet · testnet · devnet',
      devnet: '本地部署（每个 devnet 的地址不同）'
    },
    fr: {
      sdk: 'SDK',
      network: 'Réseau',
      contracts: 'Contrats',
      all: 'Toutes les adresses',
      allNetworks: 'mainnet · testnet · devnet',
      devnet: 'Déploiement local (adresses propres à chaque devnet)'
    }
  };
  const t = LABELS[lang] ?? LABELS.en;
  const contractsPage = lang === 'en' ? '/reference/contracts' : `/${lang}/reference/contracts`;
  const short = a => `${a.slice(0, 6)}…${a.slice(-4)}`;
  const entries = [];
  const addrs = ADDRESSES[network];
  if (addrs) {
    for (const p of products) {
      for (const [name, address] of Object.entries(addrs[p] ?? ({}))) entries.push({
        name,
        address
      });
    }
  }
  let contractsCell;
  if (network === 'devnet' && products.length > 0) {
    contractsCell = <span>{t.devnet}</span>;
  } else if (entries.length > 0) {
    contractsCell = entries.map(({name, address}, i) => <span key={name}>
        {i > 0 && <span className="mx-1 opacity-50">·</span>}
        {name}{' '}
        <a href={EXPLORERS[network] + address} target="_blank" rel="noreferrer" title={address}>
          <code>{short(address)}</code>
        </a>
      </span>);
  }
  const row = (label, value) => <div className="flex flex-wrap gap-x-2">
      <span className="font-semibold min-w-[5.5rem]">{label}</span>
      <span className="flex-1 min-w-0 break-words">{value}</span>
    </div>;
  return <div className="not-prose mb-6 rounded-xl border border-zinc-950/10 dark:border-white/10 bg-zinc-50 dark:bg-white/5 px-4 py-3 text-sm leading-6 text-zinc-700 dark:text-zinc-300">
      {row(t.sdk, <code>@alephium/powfi-sdk@{SDK_VERSION}</code>)}
      {row(t.network, network === 'all' ? t.allNetworks : network)}
      {contractsCell && row(t.contracts, <span>
            {contractsCell}
            <span className="mx-1 opacity-50">·</span>
            <a href={contractsPage}>{t.all} →</a>
          </span>)}
    </div>;
};

<VersionBanner network="mainnet" products={['cpmm', 'clmm', 'staking']} lang="en" />

All typed errors extend `PowfiSDKError`, which extends `Error`. Import them from the package root and narrow with `instanceof`:

```ts theme={null}
import {
  PowfiSDKError,
  PoolNotFoundError,
  PriceImpactTooHighError,
  InsufficientBalanceError,
  InsufficientLiquidityError
} from '@alephium/powfi-sdk'

try {
  await powfi.cpmm.swap(req, balances)
} catch (e) {
  if (e instanceof PriceImpactTooHighError) showWarning(e.message)
  else if (e instanceof InsufficientBalanceError) showTopUp(e.message)
  else if (e instanceof PoolNotFoundError) showCreatePool()
  else throw e
}
```

## Typed errors

| Error | Thrown by | Message |
| - | - | - |
| `PoolNotFoundError` | `cpmm.getPoolState`, `clmm.getPoolState`, `clmm.getPoolTokenBalances`, `clmm.findBestRoute` | `Pool does not exist for <poolId>` |
| `PriceImpactTooHighError` | `cpmm.swap` when `priceImpact >= 5` | `Price impact too high: 6.12% > 5%` |
| `InsufficientBalanceError` | `cpmm.swap`, `cpmm.addLiquidity` when you pass a `balances` map | `Not enough <SYMBOL> balance. Required: …, Available: …` |
| `InsufficientLiquidityError` | `CpmmModule.getAmountIn` (output ≥ reserve), `getInitLiquidityDetails` (initial liquidity ≤ `MINIMUM_LIQUIDITY`) | `Insufficient liquidity` / custom |
| `TokenListFetchError` | `token.fetchTokens` (wrapped, see below) | `Failed to fetch token list from <url> (status 404)` |

`TokenListFetchError` exposes `status?: number` and the original error as `cause`.

<Note>
  Some module methods catch errors and re-throw them as a plain `Error` with a combined message (via `logAndThrowError`), for example `Failed to fetch pool state on <id>, <original message>`. `TokenModule.getTokens()` and `fetchTokens()` behave this way, so the `TokenListFetchError` text appears in the message but the thrown object is an `Error`. Match on the message if you need to tell them apart.
</Note>

## Validation errors (plain `Error`)

| Message | Cause |
| - | - |
| `Signer not set` | A write method was called on an instance loaded without `signer`. |
| `Network <id> not found` | Unknown `networkId`. |
| `Either amountIn or amountOut must be specified` | CPMM quote with neither amount. |
| `Slippage must satisfy 0 <= slippage < 10000, received …` | Invalid `slippageBps` for CPMM. |
| `slippageBps must be in [0, 10000)` | Invalid slippage for CLMM. |
| `Unknown tokenInId … for pool …` | Token not part of the pool state you passed. |
| `Unknown token, id not found in token list: …` | Token missing from the token list (pool state lookups need every pool token to be listed). |
| `fee and feeRecipient must be provided together` (and other fee messages) | Invalid [integrator fee](/guides/integrator-fees). |
| `<Stake/Unstake/Claim> amount must be greater than zero` | Non-positive staking amount. |
| `TickOutOfBounds: <tick>` / `SqrtPriceX96OutOfBounds` | Tick outside `[MIN_TICK, MAX_TICK]` or price outside the representable range. |

## On-chain errors

If a transaction passes SDK validation but fails in the contract (slippage exceeded, deadline passed, price limit violated), the node rejects it during signing and `@alephium/web3` throws with the VM error code in the message, for example `Error Code: 501` when a CLMM swap hits its price limit before filling the full amount (`106` if the limit is on the wrong side of the price). The most common causes:

* **Slippage or deadline**: the pool moved between quote and submission. Re-quote and retry.
* **Insufficient ALPH for dust or deposits**: see [ALPH deposits and dust](/concepts/amounts-and-slippage#alph-deposits-and-dust).
* **Wrong direction or price limit on CLMM `swapTo`**: the target price is already past the current price.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.