npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@paraspell/xcm-router

v12.5.1

Published

Tool for XCM cross-chain asset exchanging across Polkadot and Kusama ecosystems

Readme

Implemented exchanges | Swap Type | DEX | Pools | Notes | |------------|-------------------|-------|--------------------------------------| | One-click | Hydration | 210 | — | | One-click | AssetHub Polkadot | 32 | Requires specific native tokens | | Two-click | Acala | 36 | Requires native token | | Two-click | Basilisk | 15 | — | | Two-click | Bifrost Kusama | 66 | Requires native token | | Two-click | Bifrost Polkadot | 45 | Requires native token | | Two-click | Karura | 136 | Requires native token | | Two-click | AssetHub Kusama | 16 | Requires specific native tokens |

Total pools available: 556

[!NOTE]

  • 📣 Some exchanges require native tokens to proceed with swaps.

  • 📣 Router supports one-click cross-chain swaps! Supported exchanges are AssetHubPolkadot and Hydration.

    • 📋 Sidenote: Not all chains can be selected as origin for one-click cross-chain swaps, because their barrier doesn't support execute extrinsic. All chains can be selected as a destination, however. For origin chains that do not support execute extrinsic, we automatically default to the original two-click scenario.

Installation

Install dependencies

[!IMPORTANT]

  • ⚠️ WebAssembly (Wasm) must be enabled in your project because of the Hydration SDK (One of the exchanges implemented in XCM Router). Wasm can be enabled either through the web application configuration or through the appropriate plugin. Additionally, Hydration requires the use of the augment package (see: https://github.com/galacticcouncil/sdk/issues/114).

  • ⚠️ XCM Router has been migrated to the PAPI library. If you used XCM Router prior to migration, replace the legacy Polkadot.js (PJS) injector with the PAPI signer and install the newly required peer dependency. Follow the setup guide for more information.

yarn add || pnpm | npm install polkadot-api

Install XCM Router

yarn add || pnpm | npm install @paraspell/xcm-router

Importing package to your project

Builder:

import { RouterBuilder } from '@paraspell/xcm-router'

Other exposed functions/ways:

// ESM
import * as xcmRouter from '@paraspell/xcm-router'

//Multiple import options
import { transfer, 
         TransactionType, 
         TTransferOptions, 
         TTxProgressInfo } from '@paraspell/xcm-router'

//As Polkadot moves to ESM only, our Router also moves to ESM only. CJS is not supported anymore.

Implementation

Automatic exchange selection (Based on best price)

If you wish to have an exchange chain selection based on the best price outcome, you can opt for an automatic exchange selection method. This method can be selected by not using the .exchange() parameter in the call. The router will then automatically select the best exchange chain for you based on the best price outcome. You can find out more in official documentation.

await RouterBuilder(/*builder config - optional (More info in docs)*/)
       .from(TSubstrateChain)   //Origin Parachain/Relay chain - OPTIONAL PARAMETER
       .to(TChain)    //Destination Parachain/Relay chain - OPTIONAL PARAMETER
       .currencyFrom(currencyFrom)    // Currency to send {id: currencyID, amount: amount} | {symbol: currencySymbol, amount: amount} | {symbol: Native('currencySymbol'), amount: amount} | {symbol: Foreign('currencySymbol'), amount: amount} | {symbol: ForeignAbstract('currencySymbol'), amount: amount} | {location: AssetLocationString, amount: amount | AssetLocationJson, amount: amount}
       .currencyTo(currencyTo)    // Currency to receive {id: currencyID, amount: amount} | {symbol: currencySymbol, amount: amount} | {symbol: Native('currencySymbol'), amount: amount} | {symbol: Foreign('currencySymbol'), amount: amount} | {symbol: ForeignAbstract('currencySymbol'), amount: amount} | {location: AssetLocationString, amount: amount | AssetLocationJson, amount: amount}
       .amount(amount)  // Amount to send
       .slippagePct(pct)   // Max slipppage percentage
       .senderAddress(injectorAddress)   //Injector address
       .recipientAddress(recipientAddress) //Recipient address
       .signer(signer)    //PAPI Signer
       //.evmSenderAddress(evmInjector address)   //Optional parameters when origin chain is EVM based (Required with evmSigner)
       //.evmSigner(EVM signer)                     //Optional parameters when origin chain is EVM based (Required with evmInjectorAddress)

       .onStatusChange((status: TRouterEvent) => {  //This is how we subscribe to calls that need signing
         console.log(status.type);   // Current transaction type
         console.log(status.routerPlan);   // Array of all transactions to execute
         console.log(status.chain);   // Current transaction origin chain
         console.log(status.destinationChain);    // Current transaction destination chain
         console.log(status.currentStep);    // 0-based step index of current transaction
       })
       .buildAndSend()

Whitelist exchange selection

If you wish to have specific exchanges selection and select the best one among them based on the best price outcome, you can opt for the whitelist automatic exchange selection method. This method can be selected by using .exchange() parameter in the call and feeding it with array of exchanges. The router will then automatically select the best exchange chain for you based on the best price outcome. You can find out more in official documentation.

await RouterBuilder(/*builder config - optional (More info in docs)*/)
        .from(TSubstrateChain)   //Origin Parachain/Relay chain - OPTIONAL PARAMETER
        .to(TChain)    //Destination Parachain/Relay chain - OPTIONAL PARAMETER
        .exchange(['HydrationDex','AcalaDex','AssetHubPolkadotDex'])    //Exchange Parachains
        .currencyFrom(currencyFrom)    // Currency to send {id: currencyID, amount: amount} | {symbol: currencySymbol, amount: amount} | {symbol: Native('currencySymbol'), amount: amount} | {symbol: Foreign('currencySymbol'), amount: amount} | {symbol: ForeignAbstract('currencySymbol'), amount: amount} | {location: AssetLocationString, amount: amount | AssetLocationJson, amount: amount}
        .currencyTo(currencyTo)    // Currency to receive {id: currencyID, amount: amount} | {symbol: currencySymbol, amount: amount} | {symbol: Native('currencySymbol'), amount: amount} | {symbol: Foreign('currencySymbol'), amount: amount} | {symbol: ForeignAbstract('currencySymbol'), amount: amount} | {location: AssetLocationString, amount: amount | AssetLocationJson, amount: amount}
        .amount(amount)  // Amount to send
        .slippagePct(pct)   // Max slipppage percentage
        .senderAddress(selectedAccount.address)   //Injector address
        .recipientAddress(recipientAddress) //Recipient address
        .signer(signer)    //PAPI Signer
        //.evmSenderAddress(evmInjector address)   //Optional parameters when origin chain is EVM based (Required with evmSigner)
        //.evmSigner(EVM signer)                     //Optional parameters when origin chain is EVM based (Required with evmInjectorAddress)

        .onStatusChange((status: TRouterEvent) => {  //This is how we subscribe to calls that need signing
          console.log(status.type);   // Current transaction type
          console.log(status.routerPlan);   // Array of all transactions to execute
          console.log(status.chain);   // Current transaction origin chain
          console.log(status.destinationChain);    // Current transaction destination chain
          console.log(status.currentStep);    // 0-based step index of current transaction
        })
        .buildAndSend()

Manual exchange selection

If you wish to select your exchange chain manually, you can provide the additional .exchange() parameter to the call. The router will then use the exchange chain of your choice. You can find out more in official documentation.

await RouterBuilder(/*builder config - optional (More info in docs)*/)
       .from(TSubstrateChain)   //Origin Parachain/Relay chain - OPTIONAL PARAMETER
       .to(TChain)    //Destination Parachain/Relay chain - OPTIONAL PARAMETER
       .exchange(exchange)    //Exchange Parachain
       .currencyFrom(currencyFrom)    // Currency to send {id: currencyID, amount: amount} | {symbol: currencySymbol, amount: amount} | {symbol: Native('currencySymbol'), amount: amount} | {symbol: Foreign('currencySymbol'), amount: amount} | {symbol: ForeignAbstract('currencySymbol'), amount: amount} | {location: AssetLocationString, amount: amount | AssetLocationJson, amount: amount}
       .currencyTo(currencyTo)    // Currency to receive {id: currencyID, amount: amount} | {symbol: currencySymbol, amount: amount} | {symbol: Native('currencySymbol'), amount: amount} | {symbol: Foreign('currencySymbol'), amount: amount} | {symbol: ForeignAbstract('currencySymbol'), amount: amount} | {location: AssetLocationString, amount: amount | AssetLocationJson, amount: amount}
       .amount(amount)  // Amount to send
       .slippagePct(pct)   // Max slipppage percentage
       .senderAddress(selectedAccount.address)   //Injector address
       .recipientAddress(recipientAddress) //Recipient address
       .signer(signer)    //PAPI Signer
       //.evmSignerAddress(evmInjector address)   //Optional parameters when origin chain is EVM based (Required with evmSigner)
       //.evmSigner(EVM signer)                     //Optional parameters when origin chain is EVM based (Required with evmInjectorAddress)

       .onStatusChange((status: TRouterEvent) => {  //This is how we subscribe to calls that need signing
         console.log(status.type);   // Current transaction type
         console.log(status.routerPlan);   // Array of all transactions to execute
         console.log(status.chain);   // Current transaction origin chain
         console.log(status.destinationChain);    // Current transaction destination chain
         console.log(status.currentStep);    // 0-based step index of current transaction
       })
       .buildAndSend()

Get amount out for your currency pair

To retrieve exchange amount, that you receive for your desired asset pair you can use following function. This function returns 2 parameters. Name of best fitting DEX (Automatic selection - can be further used for manual selection) and Amount out. You can find out more in official documentation.

const result = await RouterBuilder(/*builder config - optional (More info in docs)*/)
      .from(TSubstrateChain) //Optional parameter based on scenario
      .to(TChain) //Optional parameter based on scenario
      .exchange(exchange) //Optional parameter based on scenario
      .currencyFrom(currencyFrom)
      .currencyTo(currencyTo)
      .amount(amount)
      .getBestAmountOut();

console.log(result.amountOut)
console.log(result.exchange)

Get Router fees

You can retrieve fees for all operations XCM Router performs. Find out the example output of this function in the official documentation.

const fees = await RouterBuilder(/*builder config - optional (More info in docs)*/)
      .from(TSubstrateChain) //Optional parameter based on scenario
      .to(TChain) //Optional parameter based on scenario
      .exchange(exchange) //Optional parameter based on scenario
      .currencyFrom(currencyFrom)
      .currencyTo(currencyTo)
      .amount(amount)
      .senderAddress(senderAddress)
      .recipientAddress(recipientAddress)
      .slippagePct(slippagePct)
      .getXcmFees();

Dryrun router call

You can find out whether router dryrun call will execute correctly (works for 2 signature transfers also). You can find out more in official documentation.

const fees = await RouterBuilder(/*builder config - optional (More info in docs)*/)
      .from(TSubstrateChain) //Optional parameter based on scenario
      .to(TChain) //Optional parameter based on scenario
      .exchange(exchange) //Optional parameter based on scenario
      .currencyFrom(currencyFrom)
      .currencyTo(currencyTo)
      .amount(amount)
      .senderAddress(senderAddress)
      .recipientAddress(recipientAddress)
      .slippagePct(slippagePct)
      .dryRun();

Get minimal transferable amount

You can find out minimal amount you need to transfer in order to get the currency swapped (Does not guarantee it will be enough after swap). You can find out more in official documentation.

const fees = await RouterBuilder(/*builder config - optional (More info in docs)*/)
      .from(TSubstrateChain) //Optional parameter based on scenario
      .to(TChain) //Optional parameter based on scenario
      .exchange(exchange) //Optional parameter based on scenario
      .currencyFrom(currencyFrom)
      .currencyTo(currencyTo)
      .amount(amount)
      .senderAddress(senderAddress)
      .recipientAddress(recipientAddress)
      .slippagePct(slippagePct)
      .getMinTransferableAmount();

Get maximal transferable amount

You can find out maximal amount of specific currency you can transfer while staying above existential deposit and leaving enough to cover execution fees on origin (If needed). You can find out more in official documentation.

const fees = await RouterBuilder(/*builder config - optional (More info in docs)*/)
      .from(TSubstrateChain) //Optional parameter based on scenario
      .to(TChain) //Optional parameter based on scenario
      .exchange(exchange) //Optional parameter based on scenario
      .currencyFrom(currencyFrom)
      .currencyTo(currencyTo)
      .amount(amount)
      .senderAddress(senderAddress)
      .recipientAddress(recipientAddress)
      .slippagePct(slippagePct)
      .getTransferableAmount();

Helpful functions

Below, you can find helpful functions that are exported from XCM Router to help you enhance front end usability of XCM Router. You can find out more in official documentation.

import {getExchangeAssets, getExchangePairs} from @paraspell/xcm-router

//Returns all assets that DEX supports
const assets = getExchangeAssets('AssetHubPolkadotDex')

//Returns asset pairs supported by selected exchanges
const pairs = getExchangePairs(exchange) // exchange can be also array of exchanges such as [“HydrationDex”, “AcalaDex”] or undefined which will return all available pairs for all dexes

💻 Testing

  • Run compilation using pnpm compile

  • Run linting test using pnpm lint

  • Run unit tests using pnpm test

[!NOTE] XCM Router can be tested in Playground.

Contribute to XCM Tools and earn rewards 💰

We run an open Bug Bounty Program that rewards contributors for reporting and fixing bugs in the project. More information on bug bounty can be found in the official documentation.

Get Support 🚑

License

Made with 💛 by ParaSpell✨

Published under MIT License.

Supported by