Installation
Install dependencies
ParaSpell XCM SDK is the 🥇 in the ecosystem to support both PolkadotJS and PolkadotAPI.
This version of SDK uses PolkadotAPI if you wish to use PolkadotJS version please reffer to following package.
pnpm | npm install || yarn add polkadot-api
Install SDK
pnpm | npm install || yarn add @paraspell/sdk
Importing package to your project
Builder pattern:
import { Builder } from '@paraspell/sdk'
Other patterns:
import * as paraspell from '@paraspell/sdk'
Interaction with further asset symbol abstraction:
import { Native, Foreign, ForeignAbstract } from '@paraspell/sdk';
Implementation
NOTES:
- You can now query Ethereum asset balances on Ethereum via balance query
- The Builder() now accepts an optional configuration object (To enhance localhost experience and testing). This object can contain apiOverrides and a development flag. More information in the "Localhost test setup" section.
- V10 > V11 Migration guide https://paraspell.github.io/docs/migration/v10-to-v11.html
- Brand new asset decimal abstraction introduced. It can be turned on in Builder config. Will be turned on by default in next major release.
Latest news:
- V11 > V12 Migration guide https://paraspell.github.io/docs/migration/v11-to-v12.html
Sending XCM
For full documentation on XCM Transfers head over to official documentation.
Transfer assets from Parachain to Parachain
const builder = Builder()
.from(TSubstrateChain)
.to(TChain | Location object )
.currency({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 } | {location: Override('Custom Location'), amount: amount } | [{currencySelection , amount: amount }, {currencySelection}, ..])
.address(address | Location object )
.senderAddress(address)
const tx = await builder.build()
await builder.disconnect()
Transfer assets from the Relay chain to the Parachain
const builder = Builder()
.from(TRelaychain)
.to(TChain | Location object)
.currency({symbol: 'DOT', amount: amount })
.address(address | Location object)
const tx = await builder.build()
await builder.disconnect()
Transfer assets from Parachain to Relay chain
const builder = Builder()
.from(TSubstrateChain)
.to(TRelaychain)
.currency({symbol: 'DOT', amount: amount })
.address(address | Location object)
const tx = await builder.build()
await builder.disconnect()
Local transfers
const builder = Builder()
.from(TSubstrateChain)
.to(TChain)
.currency({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 } | {location: Override('Custom Location'), amount: amount } | [{currencySelection , amount: amount }, {currencySelection}, ..])
.address(address)
const tx = await builder.build()
await builder.disconnect()
Batch calls
const builder = Builder()
.from(TSubstrateChain)
.to(TChain2)
.currency({currencySelection, amount})
.address(address | Location object)
.addToBatch()
.from(TSubstrateChain)
.to(TChain3)
.currency({currencySelection, amount})
.address(address | Location object)
.addToBatch()
const tx = await builder.buildBatch({
mode: BatchMode.BATCH_ALL
})
await builder.disconnect()
Asset claim:
const builder = Builder()
.claimfrom(TSubstrateChain)
.currency({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 } | [{currencySelection , amount: amount }, {currencySelection}, ..]
)
.address(address | Location object)
const tx = await builder.build()
await builder.disconnect()
Dry run your XCM Calls:
const result = await Builder()
.from(TSubstrateChain)
.to(TChain)
.currency({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 } | {location: Override('Custom Location'), amount: amount } | {[{currencySelection, isFeeAsset?: true , amount: amount }]})
.address(ADDRESS)
.senderAddress(SENDER_ADDRESS)
.dryRun()
import { hasDryRunSupport } from "@paraspell/sdk";
const result = hasDryRunSupport(TChain)
Dry run preview:
const result = await Builder()
.from(TSubstrateChain)
.to(TChain)
.currency({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 } | {location: Override('Custom Location'), amount: amount } | {[{currencySelection, isFeeAsset?: true , amount: amount }]})
.address(ADDRESS)
.senderAddress(SENDER_ADDRESS)
.dryRunPreview()
Localhost test setup
const builder = await Builder({
development: true,
decimalAbstraction: true
xcmFormatCheck: true
apiOverrides: {
Hydration:
BridgeHubPolkadot:
}
})
.from(TSubstrateChain)
.to(TChain)
.currency({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 } | {location: Override('Custom Location'), amount: amount } | [{currencySelection, isFeeAsset?: true , amount: amount }])
.address(address)
const tx = await builder.build()
await builder.disconnect()
XCM Fee queries
For full documentation with output examples of XCM Fee queries, head to official documentation.
XCM Transfer info
const info = await Builder()
.from(TSubstrateChain)
.to(TChain)
.currency(CURRENCY_SPEC)
.address(RECIPIENT_ADDRESS)
.senderAddress(SENDER_ADDRESS)
.getTransferInfo()
Transferable amount
const transferable = await Builder()
.from(TSubstrateChain)
.to(TChain)
.currency(CURRENCY_SPEC)
.address(RECIPIENT_ADDRESS)
.senderAddress(SENDER_ADDRESS)
.getTransferableAmount()
Minimal transferable amount
const transferable = await Builder()
.from(TSubstrateChain)
.to(TChain)
.currency(CURRENCY_SPEC)
.address(RECIPIENT_ADDRESS)
.senderAddress(SENDER_ADDRESS)
.getMinTransferableAmount()
Receivable amount
const receivable = await Builder()
.from(TSubstrateChain)
.to(TChain)
.currency(CURRENCY_SPEC)
.address(RECIPIENT_ADDRESS)
.senderAddress(SENDER_ADDRESS)
.getReceivableAmount()
Verify ED on destination
const ed = await Builder()
.from(TSubstrateChain)
.to(TChain)
.currency(CURRENCY_SPEC)
.address(RECIPIENT_ADDRESS)
.senderAddress(SENDER_ADDRESS)
.verifyEdOnDestination()
XCM Fee (Origin and Dest.)
const fee = await Builder()
.from(TSubstrateChain)
.to(TChain)
.currency(CURRENCY_SPEC)
.address(RECIPIENT_ADDRESS)
.senderAddress(SENDER_ADDRESS)
.getXcmFee()
XCM Fee (Origin only)
const fee = await Builder()
.from(TSubstrateChain)
.to(TChain)
.currency(CURRENCY_SPEC)
.address(RECIPIENT_ADDRESS)
.senderAddress(SENDER_ADDRESS)
.getOriginXcmFee()
Asset balance
import { getBalance } from "@paraspell/sdk";
const balance = await getBalance({ADDRESS, TChain, CURRENCY_SPEC , api });
Ethereum bridge fees
import { getParaEthTransferFees } from "@paraspell/sdk";
const fees = await getParaEthTransferFees()
Existential deposit queries
import { getExistentialDeposit } from "@paraspell/sdk";
const ed = getExistentialDeposit(Tchain, CURRENCY_SPEC?)
Convert SS58 address
import { convertSs58 } from "@paraspell/sdk";
let result = convertSs58(ADDRESS, TChain)
Asset queries
For full documentation with output examples of asset queries, head over to official documentation.
import { getSupportedDestinations, getFeeAssets, getAssetsObject, getAssetId, getRelayChainSymbol, getNativeAssets, getNativeAssets, getOtherAssets, getAllAssetsSymbols, hasSupportForAsset, getAssetDecimals, getParaId, getTChain, getAssetLocation, CHAINS, findAssetInfo, findAssetInfoOrThrow } from '@paraspell/sdk'
getSupportedDestinations(TChain, CURRENCY)
findAssetInfo(TChain, CURRENCY, DESTINATION?)
findAssetInfoOrThrow(TChain, CURRENCY, DESTINATION?)
getFeeAssets(TChain)
getAssetLocation(TChain, { symbol: symbol } | { id: assetId })
getAssetsObject(TChain)
getAssetId(TChain, ASSET_SYMBOL)
getRelayChainSymbol(TChain)
getNativeAssets(TChain)
getOtherAssets(TChain)
getAllAssetsSymbols(TChain)
hasSupportForAsset(TChain, ASSET_SYMBOL)
getAssetDecimals(TChain, ASSET_SYMBOL)
getParaId(TChain)
getTChain(paraID: number, ecosystem: 'Polkadot' | 'Kusama' | 'Ethereum' | 'Paseo' | 'Westend')
CHAINS
Parachain XCM Pallet queries
For full documentation with output examples of pallet queries, head over to official documentation.
import { getDefaultPallet, getSupportedPallets, getPalletIndex, getNativeAssetsPallet, getOtherAssetsPallets, SUPPORTED_PALLETS } from '@paraspell/sdk';
getDefaultPallet(chain: TChain)
getSupportedPallets(chain: TChain)
getPalletIndex(chain: TChain)
getNativeAssetsPallet(chain: TChain)
getOtherAssetsPallets(chain: TChain)
console.log(SUPPORTED_PALLETS)
💻 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
-
Run all core tests and checks using pnpm runAll
XCM SDK 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