@paraspell/sdk
TypeScript icon, indicating that this package has built-in type declarations

5.4.1 • Public • Published



@paraspell/sdk

SDK for handling XCM asset transfers across Polkadot and Kusama ecosystems.

version downloads build snyk

Currently supporting 53 Polkadot & Kusama nodes list [here]

SDK documentation [here]





Installation

Install dependencies

pnpm | npm install || yarn add @polkadot/api @polkadot/types @polkadot/api-base @polkadot/apps-config @polkadot/util

Install SDK

pnpm | npm install || yarn add @paraspell/sdk

Importing package to your project:

Builder pattern:

import { Builder } from '@paraspell/sdk'

Other patterns:

// ESM
import * as paraspell from '@paraspell/sdk'

// CommonJS
const paraspell = require('@paraspell/sdk')

Implementation

NOTES:
- If you wish to transfer from Parachain that uses long IDs for example Moonbeam you have to add the character 'n' to the end of currencyID. Eg: .currency(42259045809535163221576417993425387648n) will mean you transfer xcDOT.
- You can now use custom ParachainIDs if you wish to test in TestNet. Just add parachainID as an additional parameter eg: .to('Basilisk', 2948)
- You can now add an optional parameter useKeepAlive which will ensure, that you send more than the existential deposit.
- Since v5 you can fully customize all multilocations (address, currency and destination). Instead of a string parameter simply pass an object with multilocation instead for more information refer to the following PR https://github.com/paraspell/xcm-tools/pull/199.
- Fee asset is now a required builder parameter when you enter a multilocation array.
- When using a multilocation array the amount parameter is overridden.
- Multilocation arrays are now available. Customize your asset multilocations by .currency([{multilocation1},{multilocation2}..{multilocationN}]) For more information refer to the official documentation or following PR https://github.com/paraspell/xcm-tools/pull/224.

Builder pattern:

Transfer assets from Parachain to Parachain
await Builder(/*node api - optional*/)
      .from(NODE)
      .to(NODE /*,customParaId - optional*/ | Multilocation object /*Only works for PolkadotXCM pallet*/) 
      .currency(CurrencyString| | CurrencyID | Multilocation object | MultilocationArray)
      /*.feeAsset(feeAsset) - Parameter required when using MultilocationArray*/
      .amount(amount) // Overriden when using MultilocationArray
      .address(address | Multilocation object /*If you are sending through xTokens, you need to pass the destination and address multilocation in one object (x2)*/)
      .build()
/*
EXAMPLE:
await Builder()
      .from('Basilisk')
      .to('Robonomics')
      .currency('XRT')
      .amount(1000000000000)
      .address('4FCUYBMe2sbq5KosN22emsPUydS8XUwZhJ6VUZesmouGu6qd')
      .build()
*/
Transfer assets from the Relay chain to Parachain
await Builder(/*node api - optional*/)
      .to(NODE/*,customParaId - optional*/ | Multilocation object)
      .amount(amount)
      .address(address | Multilocation object)
      .build()
/*
EXAMPLE:
await Builder()
      .to('AssetHubPolkadot')
      .amount(1000000000000)
      .address('141NGS2jjZca5Ss2Nysth2stJ6rimcnufCNHnh5ExSsftn7U')
      .build()
*/
Transfer assets from Parachain to Relay chain
await Builder(/*node api - optional*/)
      .from(NODE)
      .amount(amount)
      .address(address | Multilocation object)
      .build()
/*
EXAMPLE:
await Builder()
      .from('AssetHubPolkadot')
      .amount(1000000000000)
      .address('141NGS2jjZca5Ss2Nysth2stJ6rimcnufCNHnh5ExSsftn7U')
      .build()
*/
Use keepAlive option
NOTE: Custom multilocations are not available when keepALive check is used
await Builder(/*node api - optional*/)
      .from(NODE)
      .amount(amount)
      .address(address)
      .useKeepAlive(destinationParaAPI)
      .build()
Close HRMP channels
Builder(api)
.from(NODE)
.closeChannel()
.inbound(inbound)
.outbound(outbound)
.build()
Open HRMP channels
Builder()
.from(NODE)
.to(NODE)
.openChannel()
.maxSize(maxSize)
.maxMessageSize(maxMsgSize)
.build()'

Function pattern:

NOTES:
- Since version v5 there was a breaking change introduced. You now pass single object with properties instead of parameters
- Since v5 you can fully customize all multilocations (address, currency and destination). Instead of string parameter simply pass object with multilocation instead for more information refer to the following PR https://github.com/paraspell/xcm-tools/pull/199.
- Custom multilocations are not available when keepALive check is used
// Transfer assets from Parachain to Parachain
await paraspell.xcmPallet.send(
    {
      api?: ApiPromise,
      origin: origin  Parachain  name  string,
      currency: CurrencyString | CurrencyID | Multilocation object /*Only works for PolkadotXCM pallet*/,
      feeAsset? - Fee asset select id
      amount: any,
      to: destination  address  string | Multilocation object,
      destination: destination  Parachain  ID | Multilocation object /*If you are sending through xTokens, you need to pass the destination and address multilocation in one object (x2)*/,
      paraIdTo?: number,
      destApiForKeepAlive?: ApiPromise
    }
)

// Transfer assets from Parachain to Relay chain
await paraspell.xcmPallet.send(
  {
    api?: ApiPromise,
    origin: origin  Parachain  name  string,
    amount: any,
    to: destination  address  string | Multilocation object,
    paraIdTo?: number,
    destApiForKeepAlive?: ApiPromise
  }
)

// Transfer assets from Relay chain to Parachain
await paraspell.xcmPallet.transferRelayToPara(
  {
    api?: ApiPromise,
    destination: destination  Parachain  ID | Multilocation object,
    amount: any,
    to: destination  address  string | Multilocation object,
    paraIdTo?: number,
    destApiForKeepAlive?: ApiPromise
  }
)

// Close HRMP channels
paraspell.closeChannels.closeChannel(
  {
    api: ApiPromise,
    origin: origin  Parachain  ID, 
    inbound: number,
    outbound: number
  }
)

// Open HRMP channels
paraspell.openChannels.openChannel(
  {
    api: ApiPromise,
    origin: origin  Parachain  ID,
    destination: destination  Parachain  ID,
    maxSize: number,
    maxMessageSize: number
  }
)

Asset claim:

//Claim XCM trapped assets from the selected chain
await Builder(api)
      .claimFrom(NODE)
      .fungible(MultilocationArray (Only one multilocation allowed) [{Multilocation}])
      .account(address | Multilocation object)
      /*.xcmVersion(Version.V3) Optional parameter, by default V3. XCM Version ENUM if a different XCM version is needed (Supported V2 & V3). Requires importing Version enum.*/
      .build()

Asset queries:

// Retrieve assets object from assets.json for particular node including information about native and foreign assets
paraspell.assets.getAssetsObject(node: TNode)

// Retrieve foreign assetId for a particular node and asset symbol
paraspell.assets.getAssetId(node: TNode, symbol: string)

// Retrieve the symbol of the relay chain for a particular node. Either "DOT" or "KSM"
paraspell.assets.getRelayChainSymbol(node: TNode)

// Retrieve string array of native assets symbols for particular node
paraspell.assets.getNativeAssets(node: TNode)

// Retrieve object array of foreign assets for a particular node. Each object has a symbol and assetId property
paraspell.assets.getOtherAssets(node: TNode)

// Retrieve string array of all assets symbols. (native and foreign assets are merged into a single array)
paraspell.assets.getAllAssetsSymbols(node: TNode)

// Check if a node supports a particular asset. (Both native and foreign assets are searched). Returns boolean
paraspell.assets.hasSupportForAsset(node: TNode, symbol: string)

// Get decimals for specific asset
paraspell.assets.getAssetDecimals(node: TNode, symbol: string)

// Get specific node id
paraspell.assets.getParaId(node: TNode)

// Get specific TNode from nodeID
paraspell.assets.getTNode(nodeID: number)

// Import all compatible nodes as constant
paraspell.NODE_NAMES

Parachain XCM Pallet queries

import { getDefaultPallet, getSupportedPallets, SUPPORTED_PALLETS } from  '@paraspell/sdk'

//Retrieve default pallet for specific Parachain 
getDefaultPallet(node: TNode)

// Returns an array of supported pallets for a specific Parachain
getSupportedPallets(node: TNode)

// Print all pallets that are currently supported
console.log(SUPPORTED_PALLETS)

Existential deposit queries

import { getExistentialDeposit } from "@paraspell/sdk";

const ed = getExistentialDeposit('Acala')

💻 Tests

  • Run compilation using pnpm compile

  • Run linter using pnpm lint

  • Run unit tests using pnpm test

  • Run end-to-end tests using pnpm test:e2e

  • Update Parachain registered assets in the map using script - pnpm updateAssets

  • Update XCM pallets in the map using script - pnpm updatePallets

  • Update existential deposits in the map using script - pnpm updateEds

  • Run all core tests and checks using pnpm runAll

XCM SDK can be tested in Playground.

License

Made with 💛 by ParaSpell✨

Published under MIT License.

Support

Readme

Keywords

none

Package Sidebar

Install

npm i @paraspell/sdk

Weekly Downloads

675

Version

5.4.1

License

MIT

Unpacked Size

535 kB

Total Files

6

Last publish

Collaborators

  • dudo50
  • vikiival