Transfer Tokens Between Parachains¶
Introduction¶
This guide walks you through transferring tokens between two parachains using the ParaSpell XCM SDK. This example utilizes Asset Hub and the People Chain. However, the same approach can be applied to transfers between other parachains.
For development purposes, this guide will use the Polkadot TestNet, so the transferred token will be PAS.
In this guide, you will:
- Build an XCM transfer transaction using ParaSpell XCM SDK.
- Perform a dry run to validate the transfer.
- Verify the Existential Deposit (ED) requirement on the destination chain.
- Retrieve information regarding the transfer, along with fee estimates.
- Submit the transaction.
Prerequisites¶
Before you begin, ensure you have the following:
- Knowledge of the fundamentals of Polkadot.
- Basic understanding of XCM.
- Basic familiarity with JavaScript or TypeScript.
- Installed bun, a JavaScript and TypeScript package manager.
Initialize Your Project¶
Create the project folder:
Initialize the JavaScript project:
Install the required dependencies:
bun add @paraspell/sdk@11.3.2 polkadot-api@1.17.1 @polkadot-labs/hdkd-helpers@0.0.25 @polkadot-labs/hdkd@0.0.24
Now add the following setup code to index.ts
:
import { Builder, hasDryRunSupport } from '@paraspell/sdk';
import {
entropyToMiniSecret,
mnemonicToEntropy,
ss58Address,
} from '@polkadot-labs/hdkd-helpers';
import { getPolkadotSigner } from 'polkadot-api/signer';
import { sr25519CreateDerive } from '@polkadot-labs/hdkd';
import { inspect } from 'util';
// PAS token has 10 decimals
const PAS_UNITS = 10_000_000_000n;
const SEED_PHRASE =
'INSERT_YOUR_SEED_PHRASE';
// Create Sr25519 signer from mnemonic
function getSigner() {
const entropy = mnemonicToEntropy(SEED_PHRASE);
const miniSecret = entropyToMiniSecret(entropy);
const derive = sr25519CreateDerive(miniSecret);
const keyPair = derive('');
return getPolkadotSigner(keyPair.publicKey, 'Sr25519', keyPair.sign);
}
const RECIPIENT_ADDRESS = ss58Address(getSigner().publicKey);
const SENDER_ADDRESS = ss58Address(getSigner().publicKey);
Replace the INSERT_YOUR_SEED_PHRASE
with the seed phrase from your Polkadot development account.
Be sure to fund this account with some PAS tokens on Paseo's Asset Hub using the Polkadot Faucet.
Security Warning
Never commit your mnemonic phrase to production code. Use environment variables or secure key management systems.
Build a Token Transfer Transaction¶
The next step is to build the transaction that you intend to execute.
In this example, you will transfer 10 PAS tokens from Paseo's Asset Hub to Paseo's People Chain system parachain.
Add the ParaSpell transaction code to your index.ts
file:
async function transfer() {
const signer = getSigner();
const tx = await Builder()
.from('AssetHubPaseo')
.to('PeoplePaseo')
.currency({
symbol: 'PAS',
amount: 10n * PAS_UNITS, // 10 PAS
})
.address(RECIPIENT_ADDRESS)
.build();
console.log('Built transaction:', inspect(tx, { colors: true, depth: null }));
const result = await tx.signAndSubmit(signer);
console.log(inspect(result, { colors: true, depth: null }));
process.exit(0);
}
Do not execute it just yet. You will perform a dry run of this transaction first to ensure it works as expected.
Perform a Dry Run¶
Dry runs simulate the transaction without broadcasting it, allowing you to confirm success in advance.
Add the following dry run code to your index.ts
script:
async function dryRunTransfer() {
if (!hasDryRunSupport('AssetHubPaseo')) {
console.log('Dry run is not supported on AssetHubPaseo.');
return;
}
const tx = await Builder()
.from('AssetHubPaseo')
.to('PeoplePaseo')
.currency({
symbol: 'PAS',
amount: 10n * PAS_UNITS,
})
.address(RECIPIENT_ADDRESS)
.senderAddress(SENDER_ADDRESS)
.dryRun();
console.log(inspect(tx, { colors: true, depth: null }));
process.exit(0);
}
dryRunTransfer();
The result of the dry run will look similar to the following example output:
Verify the Existential Deposit¶
Check if the recipient account meets the Existential Deposit (ED) requirement before sending by using verifyEdOnDestination
:
async function verifyED() {
const isValid = await Builder()
.from('AssetHubPaseo')
.to('PeoplePaseo')
.currency({
symbol: 'PAS',
amount: 10n * PAS_UNITS,
})
.address(RECIPIENT_ADDRESS)
.senderAddress(SENDER_ADDRESS)
.verifyEdOnDestination();
console.log(`ED verification ${isValid ? 'successful' : 'failed'}.`);
process.exit(0);
}
verifyED();
dryRunTransfer()
function so that it is not executed again. Then, execute the verifyED()
by running the following command:
After that, you will get output confirming the ED which will look similar to the following:
Get Transfer Info and Fee Estimates¶
Before sending an XCM transaction, it is helpful to estimate the fees associated with executing and delivering the cross-chain message.
ParaSpell has a helpful function for this: getTransferInfo()
. This function returns an estimate of the associated XCM fees, along with the account's balance before and after the fees are paid.
async function XcmTransferInfo() {
const info = await Builder()
.from('AssetHubPaseo')
.to('PeoplePaseo')
.currency({
symbol: 'PAS',
amount: 10n * PAS_UNITS,
})
.address(RECIPIENT_ADDRESS)
.senderAddress(SENDER_ADDRESS)
.getTransferInfo();
console.log('Transfer Info:', info);
process.exit(0);
}
XcmTransferInfo();
Comment out the verifyED()
function so it doesn't execute again. Then, execute the XcmTransferInfo()
function by running the following command:
You will see all the information for your transfer similar to the following example:
Now that you have:
- Completed a successful dry run of the transaction.
- Verified the existential deposit on the recipient account.
- Obtained an estimate of the associated XCM fees.
You can execute the transfer function by adding the following function call:
Comment out the XcmTransferInfo()
function so it doesn't execute again. Then, execute the transfer by running the following command:
Your transfer
function will submit the transaction, and you will get the following output:
Once the transaction is successfully included in a block, you will see the recipient's account balance updated, and you will receive output similar to the following.
Successful Transaction Submission
This output will be returned once the transaction has been successfully included in a block.
After executing the transfer, check the account balance on Polkadot.js Apps for Paseo's Asset Hub and Paseo's People Chain.
You should see:
- The recipient account now has 10 more PAS tokens.
- The sender account has the transfer amount (10 PAS) + the fees amount debited from their account balance.
You have now successfully created and sent a cross-chain transfer using the ParaSpell XCM SDK!
Full Code
import { Builder, hasDryRunSupport } from '@paraspell/sdk';
import {
entropyToMiniSecret,
mnemonicToEntropy,
ss58Address,
} from '@polkadot-labs/hdkd-helpers';
import { getPolkadotSigner } from 'polkadot-api/signer';
import { sr25519CreateDerive } from '@polkadot-labs/hdkd';
import { inspect } from 'util';
// PAS token has 10 decimals
const PAS_UNITS = 10_000_000_000n;
const SEED_PHRASE =
'INSERT_YOUR_SEED_PHRASE';
// Create Sr25519 signer from mnemonic
function getSigner() {
const entropy = mnemonicToEntropy(SEED_PHRASE);
const miniSecret = entropyToMiniSecret(entropy);
const derive = sr25519CreateDerive(miniSecret);
const keyPair = derive('');
return getPolkadotSigner(keyPair.publicKey, 'Sr25519', keyPair.sign);
}
const RECIPIENT_ADDRESS = ss58Address(getSigner().publicKey);
const SENDER_ADDRESS = ss58Address(getSigner().publicKey);
async function transfer() {
const signer = getSigner();
const tx = await Builder()
.from('AssetHubPaseo')
.to('PeoplePaseo')
.currency({
symbol: 'PAS',
amount: 10n * PAS_UNITS, // 10 PAS
})
.address(RECIPIENT_ADDRESS)
.build();
console.log('Built transaction:', inspect(tx, { colors: true, depth: null }));
const result = await tx.signAndSubmit(signer);
console.log(inspect(result, { colors: true, depth: null }));
process.exit(0);
}
async function dryRunTransfer() {
if (!hasDryRunSupport('AssetHubPaseo')) {
console.log('Dry run is not supported on AssetHubPaseo.');
return;
}
const tx = await Builder()
.from('AssetHubPaseo')
.to('PeoplePaseo')
.currency({
symbol: 'PAS',
amount: 10n * PAS_UNITS,
})
.address(RECIPIENT_ADDRESS)
.senderAddress(SENDER_ADDRESS)
.dryRun();
console.log(inspect(tx, { colors: true, depth: null }));
process.exit(0);
}
dryRunTransfer();
async function verifyED() {
const isValid = await Builder()
.from('AssetHubPaseo')
.to('PeoplePaseo')
.currency({
symbol: 'PAS',
amount: 10n * PAS_UNITS,
})
.address(RECIPIENT_ADDRESS)
.senderAddress(SENDER_ADDRESS)
.verifyEdOnDestination();
console.log(`ED verification ${isValid ? 'successful' : 'failed'}.`);
process.exit(0);
}
verifyED();
async function XcmTransferInfo() {
const info = await Builder()
.from('AssetHubPaseo')
.to('PeoplePaseo')
.currency({
symbol: 'PAS',
amount: 10n * PAS_UNITS,
})
.address(RECIPIENT_ADDRESS)
.senderAddress(SENDER_ADDRESS)
.getTransferInfo();
console.log('Transfer Info:', info);
process.exit(0);
}
XcmTransferInfo();
transfer();
Next Steps¶
-
Read the Docs: Dive deeper into the features of the ParaSpell XCM SDK documentation.
-
Learn about XCM: Understand the underlying protocol by visiting the Introduction to XCM page in the Polkadot Docs.
| Created: October 3, 2025