Skip to content

Commit fedd3ee

Browse files
committed
Update code according to feedback
1 parent 126cf7e commit fedd3ee

File tree

3 files changed

+139
-20
lines changed

3 files changed

+139
-20
lines changed

.snippets/code/develop/toolkit/interoperability/paraspell/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getPolkadotSigner } from 'polkadot-api/signer';
88
import { sr25519CreateDerive } from '@polkadot-labs/hdkd';
99
import { inspect } from 'util';
1010

11-
// DOT/PAS has 10 decimals
11+
// PAS token has 10 decimals
1212
const PAS_UNITS = 10_000_000_000n;
1313

1414
const SEED_PHRASE =

develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description: A step-by-step guide to building, verifying, and executing a transf
99

1010
This guide walks you through transferring tokens between two parachains using the [ParaSpell XCM SDK](https://paraspell.github.io/docs/){target=\_blank}. This example uses [Asset Hub](/polkadot-protocol/architecture/system-chains/asset-hub/){target=\_blank} and the [People Chain](/polkadot-protocol/architecture/system-chains/people/){target=\_blank}, but the same approach applies to transfers between any parachain.
1111

12-
For development purposes, this guide will use the [Paseo TestNet](/develop/networks/#paseo){target=\_blank}, so the token transfer will be from Paseo's Asset Hub to Paseo's People Chain.
12+
For development purposes, this guide will use the [Polkadot TestNet](/develop/networks/#paseo){target=\_blank}, so the transferred token will be PAS.
1313

1414
You’ll learn how to:
1515

@@ -21,8 +21,10 @@ You’ll learn how to:
2121

2222
### Prerequisites
2323

24-
- Basic familiarity with JavaScript/TypeScript
2524
- Knowledge of the [fundamentals of Polkadot](/polkadot-protocol/parachain-basics/){target=\_blank}
25+
- Basic understanding of [XCM](/develop/interoperability/intro-to-xcm/){target=\_blank}
26+
- Basic familiarity with JavaScript/TypeScript
27+
- Install [bun](https://bun.com/docs/installation){target=\_blank}, a fast JavaScript/TypeScript runtime and package manager
2628

2729
## Initialize Your Project
2830

@@ -51,7 +53,7 @@ Now add the following setup code to `index.ts`:
5153
--8<-- 'code/develop/toolkit/interoperability/paraspell/index.ts:1:27'
5254
```
5355

54-
Replace the `INSERT_YOUR_SEED_PHRASE ` with the seed phrase from your Polkadot development account.
56+
Replace the `INSERT_YOUR_SEED_PHRASE` with the seed phrase from your Polkadot development account.
5557

5658
Be sure to fund this account with some PAS tokens on Paseo's Asset Hub using the [Polkadot Faucet](https://faucet.polkadot.io/?parachain=1000){target=\_blank}.
5759

@@ -62,7 +64,7 @@ Be sure to fund this account with some PAS tokens on Paseo's Asset Hub using the
6264

6365
The next step is to build the transaction that you intend to execute.
6466

65-
In this example, you will teleport 10 PAS tokens from Paseo's Asset Hub to Paseo's People Chain system parachain.
67+
In this example, you will transfer 10 PAS tokens from Paseo's Asset Hub to Paseo's People Chain system parachain.
6668

6769
Add the ParaSpell transaction code to your `index.ts` file:
6870

@@ -98,7 +100,7 @@ Check if the recipient account meets the [Existential Deposit (ED)](/polkadot-pr
98100
```ts title="index.ts"
99101
--8<-- 'code/develop/toolkit/interoperability/paraspell/index.ts:70:85'
100102
```
101-
Execute the code by running:
103+
Comment out the `dryRunTransfer()` and execute the code by running:
102104

103105
```bash
104106
bun run index.ts
@@ -118,7 +120,7 @@ ParaSpell has a helpful function for this: [`getTransferInfo()`](https://paraspe
118120
--8<-- 'code/develop/toolkit/interoperability/paraspell/index.ts:87:102'
119121
```
120122

121-
Go ahead and execute the script:
123+
Comment out the `verifyED()` and execute the script:
122124

123125
```bash
124126
bun run index.ts
@@ -134,21 +136,21 @@ Now that you have:
134136
- Verified the existential deposit on the recipient account
135137
- Obtained an estimate of the associated XCM fees
136138

137-
Now you can execute the teleport function by adding the following statement:
139+
Now you can execute the transfer function by adding the following statement:
138140

139141
Add the following code:
140142

141143
```typescript title="index.ts"
142144
--8<-- 'code/develop/toolkit/interoperability/paraspell/index.ts:104:104'
143145
```
144146

145-
And execute your teleport:
147+
Comment out the `XcmTransferInfo()` and execute the transfer:
146148

147149
```bash
148150
bun run index.ts
149151
```
150152

151-
Your `teleport` function will submit the transaction, and you will get the following output:
153+
Your `transfer` function will submit the transaction, and you will get the following output:
152154

153155
--8<-- 'code/develop/toolkit/interoperability/paraspell/transfer-output.html'
154156

@@ -168,6 +170,12 @@ You should see:
168170

169171
You have now successfully created and sent a cross-chain transfer using the ParaSpell XCM SDK!
170172

173+
???- code "Full Code"
174+
175+
```typescript title="index.ts"
176+
--8<-- 'code/develop/toolkit/interoperability/paraspell/index.ts'
177+
```
178+
171179
## Next Steps
172180

173181
- Read the Docs: Dive deeper into the features of the [ParaSpell XCM SDK](https://paraspell.github.io/docs/sdk/getting-started.html){target=\_blank} documentation.

llms-full.txt

Lines changed: 121 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17260,7 +17260,7 @@ description: A step-by-step guide to building, verifying, and executing a transf
1726017260

1726117261
This guide walks you through transferring tokens between two parachains using the [ParaSpell XCM SDK](https://paraspell.github.io/docs/){target=\_blank}. This example uses [Asset Hub](/polkadot-protocol/architecture/system-chains/asset-hub/){target=\_blank} and the [People Chain](/polkadot-protocol/architecture/system-chains/people/){target=\_blank}, but the same approach applies to transfers between any parachain.
1726217262

17263-
For development purposes, this guide will use the [Paseo TestNet](/develop/networks/#paseo){target=\_blank}, so the token transfer will be from Paseo's Asset Hub to Paseo's People Chain.
17263+
For development purposes, this guide will use the [Polkadot TestNet](/develop/networks/#paseo){target=\_blank}, so the transferred token will be PAS.
1726417264

1726517265
You’ll learn how to:
1726617266

@@ -17272,8 +17272,10 @@ You’ll learn how to:
1727217272

1727317273
### Prerequisites
1727417274

17275-
- Basic familiarity with JavaScript/TypeScript
1727617275
- Knowledge of the [fundamentals of Polkadot](/polkadot-protocol/parachain-basics/){target=\_blank}
17276+
- Basic understanding of [XCM](/develop/interoperability/intro-to-xcm/){target=\_blank}
17277+
- Basic familiarity with JavaScript/TypeScript
17278+
- Install [bun](https://bun.com/docs/installation){target=\_blank}, a fast JavaScript/TypeScript runtime and package manager
1727717279

1727817280
## Initialize Your Project
1727917281

@@ -17309,7 +17311,7 @@ import { getPolkadotSigner } from 'polkadot-api/signer';
1730917311
import { sr25519CreateDerive } from '@polkadot-labs/hdkd';
1731017312
import { inspect } from 'util';
1731117313

17312-
// DOT/PAS has 10 decimals
17314+
// PAS token has 10 decimals
1731317315
const PAS_UNITS = 10_000_000_000n;
1731417316

1731517317
const SEED_PHRASE =
@@ -17328,7 +17330,7 @@ const RECIPIENT_ADDRESS = ss58Address(getSigner().publicKey);
1732817330
const SENDER_ADDRESS = ss58Address(getSigner().publicKey);
1732917331
```
1733017332

17331-
Replace the `INSERT_YOUR_SEED_PHRASE ` with the seed phrase from your Polkadot development account.
17333+
Replace the `INSERT_YOUR_SEED_PHRASE` with the seed phrase from your Polkadot development account.
1733217334

1733317335
Be sure to fund this account with some PAS tokens on Paseo's Asset Hub using the [Polkadot Faucet](https://faucet.polkadot.io/?parachain=1000){target=\_blank}.
1733417336

@@ -17339,7 +17341,7 @@ Be sure to fund this account with some PAS tokens on Paseo's Asset Hub using the
1733917341

1734017342
The next step is to build the transaction that you intend to execute.
1734117343

17342-
In this example, you will teleport 10 PAS tokens from Paseo's Asset Hub to Paseo's People Chain system parachain.
17344+
In this example, you will transfer 10 PAS tokens from Paseo's Asset Hub to Paseo's People Chain system parachain.
1734317345

1734417346
Add the ParaSpell transaction code to your `index.ts` file:
1734517347

@@ -17554,7 +17556,7 @@ async function verifyED() {
1755417556

1755517557
verifyED();
1755617558
```
17557-
Execute the code by running:
17559+
Comment out the `dryRunTransfer()` and execute the code by running:
1755817560

1755917561
```bash
1756017562
bun run index.ts
@@ -17592,7 +17594,7 @@ async function XcmTransferInfo() {
1759217594
XcmTransferInfo();
1759317595
```
1759417596

17595-
Go ahead and execute the script:
17597+
Comment out the `verifyED()` and execute the script:
1759617598

1759717599
```bash
1759817600
bun run index.ts
@@ -17656,21 +17658,21 @@ Now that you have:
1765617658
- Verified the existential deposit on the recipient account
1765717659
- Obtained an estimate of the associated XCM fees
1765817660

17659-
Now you can execute the teleport function by adding the following statement:
17661+
Now you can execute the transfer function by adding the following statement:
1766017662

1766117663
Add the following code:
1766217664

1766317665
```typescript title="index.ts"
1766417666
transfer();
1766517667
```
1766617668

17667-
And execute your teleport:
17669+
Comment out the `XcmTransferInfo()` and execute the transfer:
1766817670

1766917671
```bash
1767017672
bun run index.ts
1767117673
```
1767217674

17673-
Your `teleport` function will submit the transaction, and you will get the following output:
17675+
Your `transfer` function will submit the transaction, and you will get the following output:
1767417676

1767517677
<div id="termynal" data-termynal>
1767617678
<span data-ty="input"><span class="file-path"></span>bun run index.ts</span>
@@ -18004,6 +18006,115 @@ You should see:
1800418006

1800518007
You have now successfully created and sent a cross-chain transfer using the ParaSpell XCM SDK!
1800618008

18009+
???- code "Full Code"
18010+
18011+
```typescript title="index.ts"
18012+
import { Builder, hasDryRunSupport } from '@paraspell/sdk';
18013+
import {
18014+
entropyToMiniSecret,
18015+
mnemonicToEntropy,
18016+
ss58Address,
18017+
} from '@polkadot-labs/hdkd-helpers';
18018+
import { getPolkadotSigner } from 'polkadot-api/signer';
18019+
import { sr25519CreateDerive } from '@polkadot-labs/hdkd';
18020+
import { inspect } from 'util';
18021+
18022+
// PAS token has 10 decimals
18023+
const PAS_UNITS = 10_000_000_000n;
18024+
18025+
const SEED_PHRASE =
18026+
'INSERT_YOUR_SEED_PHRASE';
18027+
18028+
// Create Sr25519 signer from mnemonic
18029+
function getSigner() {
18030+
const entropy = mnemonicToEntropy(SEED_PHRASE);
18031+
const miniSecret = entropyToMiniSecret(entropy);
18032+
const derive = sr25519CreateDerive(miniSecret);
18033+
const keyPair = derive('');
18034+
return getPolkadotSigner(keyPair.publicKey, 'Sr25519', keyPair.sign);
18035+
}
18036+
18037+
const RECIPIENT_ADDRESS = ss58Address(getSigner().publicKey);
18038+
const SENDER_ADDRESS = ss58Address(getSigner().publicKey);
18039+
18040+
async function transfer() {
18041+
const signer = getSigner();
18042+
18043+
const tx = await Builder()
18044+
.from('AssetHubPaseo')
18045+
.to('PeoplePaseo')
18046+
.currency({
18047+
symbol: 'PAS',
18048+
amount: 10n * PAS_UNITS, // 10 PAS
18049+
})
18050+
.address(RECIPIENT_ADDRESS)
18051+
.build();
18052+
18053+
console.log('Built transaction:', inspect(tx, { colors: true, depth: null }));
18054+
18055+
const result = await tx.signAndSubmit(signer);
18056+
console.log(inspect(result, { colors: true, depth: null }));
18057+
}
18058+
18059+
async function dryRunTransfer() {
18060+
if (!hasDryRunSupport('AssetHubPaseo')) {
18061+
console.log('Dry run is not supported on AssetHubPaseo.');
18062+
return;
18063+
}
18064+
18065+
const tx = await Builder()
18066+
.from('AssetHubPaseo')
18067+
.to('PeoplePaseo')
18068+
.currency({
18069+
symbol: 'PAS',
18070+
amount: 10n * PAS_UNITS,
18071+
})
18072+
.address(RECIPIENT_ADDRESS)
18073+
.senderAddress(SENDER_ADDRESS)
18074+
.dryRun();
18075+
18076+
console.log(inspect(tx, { colors: true, depth: null }));
18077+
}
18078+
18079+
dryRunTransfer();
18080+
18081+
async function verifyED() {
18082+
const isValid = await Builder()
18083+
.from('AssetHubPaseo')
18084+
.to('PeoplePaseo')
18085+
.currency({
18086+
symbol: 'PAS',
18087+
amount: 10n * PAS_UNITS,
18088+
})
18089+
.address(RECIPIENT_ADDRESS)
18090+
.senderAddress(SENDER_ADDRESS)
18091+
.verifyEdOnDestination();
18092+
18093+
console.log(`ED verification ${isValid ? 'successful' : 'failed'}.`);
18094+
}
18095+
18096+
verifyED();
18097+
18098+
async function XcmTransferInfo() {
18099+
const info = await Builder()
18100+
.from('AssetHubPaseo')
18101+
.to('PeoplePaseo')
18102+
.currency({
18103+
symbol: 'PAS',
18104+
amount: 10n * PAS_UNITS,
18105+
})
18106+
.address(RECIPIENT_ADDRESS)
18107+
.senderAddress(SENDER_ADDRESS)
18108+
.getTransferInfo();
18109+
18110+
console.log('Transfer Info:', info);
18111+
}
18112+
18113+
XcmTransferInfo();
18114+
18115+
transfer();
18116+
```
18117+
1800718118
## Next Steps
1800818119

1800918120
- Read the Docs: Dive deeper into the features of the [ParaSpell XCM SDK](https://paraspell.github.io/docs/sdk/getting-started.html){target=\_blank} documentation.

0 commit comments

Comments
 (0)