Skip to content

Commit c917776

Browse files
brunopgalvaonhussein11Telucerodawnkelly09
authored
Add guide on transferring tokens between parachains (#973)
* WIP: Creating ParaSpell transfer guide * WIP * Add ParaSpell transfer guide * Update develop/toolkit/interoperability/paraspell/index.md Co-authored-by: Nicolás Hussein <[email protected]> * Update develop/toolkit/interoperability/paraspell/paraspell-xcm-sdk.md Co-authored-by: Nicolás Hussein <[email protected]> * Update develop/toolkit/interoperability/paraspell/paraspell-xcm-sdk.md Co-authored-by: Nicolás Hussein <[email protected]> * Update develop/toolkit/interoperability/paraspell/paraspell-xcm-sdk.md Co-authored-by: Nicolás Hussein <[email protected]> * Update develop/toolkit/interoperability/paraspell/paraspell-xcm-sdk.md Co-authored-by: Nicolás Hussein <[email protected]> * Update content * Update content * Update develop/toolkit/interoperability/paraspell-xcm-sdk/teleport-from-asset-hub-to-relay-chain.md Co-authored-by: Taylor Lucero <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/teleport-from-asset-hub-to-relay-chain.md Co-authored-by: Taylor Lucero <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/teleport-from-asset-hub-to-relay-chain.md Co-authored-by: Taylor Lucero <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/teleport-from-asset-hub-to-relay-chain.md Co-authored-by: Taylor Lucero <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/teleport-from-asset-hub-to-relay-chain.md Co-authored-by: Taylor Lucero <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/index.md Co-authored-by: Taylor Lucero <[email protected]> * Update content * Update content * Update develop/toolkit/interoperability/paraspell-xcm-sdk/teleport-from-asset-hub-to-bridge-hub.md Co-authored-by: Nicolás Hussein <[email protected]> * Update content * llms * Revise for AH to People Chain * Update title * Fix content * Revise content to generic XCM transfer between parachains * Pin dependencies * Update wording in content * Update content to reflect generic nature of tutorial * Update code according to feedback * Update content * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * python3 scripts/generate_llms.py * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update develop/toolkit/interoperability/paraspell-xcm-sdk/transfer-tokens-between-parachains.md Co-authored-by: Dawn Kelly <[email protected]> * Update content --------- Co-authored-by: Nicolás Hussein <[email protected]> Co-authored-by: Taylor Lucero <[email protected]> Co-authored-by: Dawn Kelly <[email protected]>
1 parent 75f2841 commit c917776

File tree

11 files changed

+1683
-1
lines changed

11 files changed

+1683
-1
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<div id="termynal" data-termynal>
2+
<span data-ty="input"><span class="file-path"></span>bun run index.ts</span>
3+
<span data-ty>{
4+
failureReason: undefined,
5+
failureChain: undefined,
6+
origin: {
7+
success: true,
8+
fee: 17965000n,
9+
currency: 'PAS',
10+
asset: {
11+
symbol: 'PAS',
12+
isNative: true,
13+
decimals: 10,
14+
existentialDeposit: '100000000',
15+
location: { parents: 1, interior: { Here: null } },
16+
isFeeAsset: true,
17+
amount: 100000000000n
18+
},
19+
weight: undefined,
20+
forwardedXcms: [
21+
{
22+
type: 'V3',
23+
value: {
24+
parents: 1,
25+
interior: { type: 'X1', value: { type: 'Parachain', value: 1004 } }
26+
}
27+
},
28+
[
29+
{
30+
type: 'V3',
31+
value: [
32+
{
33+
type: 'ReceiveTeleportedAsset',
34+
value: [
35+
{
36+
id: {
37+
type: 'Concrete',
38+
value: {
39+
parents: 1,
40+
interior: { type: 'Here', value: undefined }
41+
}
42+
},
43+
fun: { type: 'Fungible', value: 100000000000n }
44+
}
45+
]
46+
},
47+
{ type: 'ClearOrigin', value: undefined },
48+
{
49+
type: 'BuyExecution',
50+
value: {
51+
fees: {
52+
id: {
53+
type: 'Concrete',
54+
value: {
55+
parents: 1,
56+
interior: { type: 'Here', value: undefined }
57+
}
58+
},
59+
fun: { type: 'Fungible', value: 100000000000n }
60+
},
61+
weight_limit: { type: 'Unlimited', value: undefined }
62+
}
63+
},
64+
{
65+
type: 'DepositAsset',
66+
value: {
67+
assets: {
68+
type: 'Wild',
69+
value: { type: 'AllCounted', value: 1 }
70+
},
71+
beneficiary: {
72+
parents: 0,
73+
interior: {
74+
type: 'X1',
75+
value: {
76+
type: 'AccountId32',
77+
value: {
78+
network: undefined,
79+
id: FixedSizeBinary {
80+
asText: [Function (anonymous)],
81+
asHex: [Function (anonymous)],
82+
asOpaqueHex: [Function (anonymous)],
83+
asBytes: [Function (anonymous)],
84+
asOpaqueBytes: [Function (anonymous)]
85+
}
86+
}
87+
}
88+
}
89+
}
90+
}
91+
},
92+
{
93+
type: 'SetTopic',
94+
value: FixedSizeBinary {
95+
asText: [Function (anonymous)],
96+
asHex: [Function (anonymous)],
97+
asOpaqueHex: [Function (anonymous)],
98+
asBytes: [Function (anonymous)],
99+
asOpaqueBytes: [Function (anonymous)]
100+
}
101+
}
102+
]
103+
}
104+
]
105+
],
106+
destParaId: 1004
107+
},
108+
assetHub: undefined,
109+
bridgeHub: undefined,
110+
destination: {
111+
success: true,
112+
fee: 817598n,
113+
currency: 'PAS',
114+
asset: {
115+
symbol: 'PAS',
116+
isNative: true,
117+
decimals: 10,
118+
existentialDeposit: '1000000000',
119+
location: { parents: 1, interior: { Here: null } },
120+
isFeeAsset: true
121+
},
122+
weight: { refTime: 176858000n, proofSize: 0n },
123+
forwardedXcms: [],
124+
destParaId: undefined
125+
},
126+
hops: []
127+
}</span>
128+
</div>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div id="termynal" data-termynal>
2+
<span data-ty="input"><span class="file-path"></span>bun run index.ts</span>
3+
<span data-ty>ED verification successful.</span>
4+
</div>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import { Builder, hasDryRunSupport } from '@paraspell/sdk';
2+
import {
3+
entropyToMiniSecret,
4+
mnemonicToEntropy,
5+
ss58Address,
6+
} from '@polkadot-labs/hdkd-helpers';
7+
import { getPolkadotSigner } from 'polkadot-api/signer';
8+
import { sr25519CreateDerive } from '@polkadot-labs/hdkd';
9+
import { inspect } from 'util';
10+
11+
// PAS token has 10 decimals
12+
const PAS_UNITS = 10_000_000_000n;
13+
14+
const SEED_PHRASE =
15+
'INSERT_YOUR_SEED_PHRASE';
16+
17+
// Create Sr25519 signer from mnemonic
18+
function getSigner() {
19+
const entropy = mnemonicToEntropy(SEED_PHRASE);
20+
const miniSecret = entropyToMiniSecret(entropy);
21+
const derive = sr25519CreateDerive(miniSecret);
22+
const keyPair = derive('');
23+
return getPolkadotSigner(keyPair.publicKey, 'Sr25519', keyPair.sign);
24+
}
25+
26+
const RECIPIENT_ADDRESS = ss58Address(getSigner().publicKey);
27+
const SENDER_ADDRESS = ss58Address(getSigner().publicKey);
28+
29+
async function transfer() {
30+
const signer = getSigner();
31+
32+
const tx = await Builder()
33+
.from('AssetHubPaseo')
34+
.to('PeoplePaseo')
35+
.currency({
36+
symbol: 'PAS',
37+
amount: 10n * PAS_UNITS, // 10 PAS
38+
})
39+
.address(RECIPIENT_ADDRESS)
40+
.build();
41+
42+
console.log('Built transaction:', inspect(tx, { colors: true, depth: null }));
43+
44+
const result = await tx.signAndSubmit(signer);
45+
console.log(inspect(result, { colors: true, depth: null }));
46+
process.exit(0);
47+
}
48+
49+
async function dryRunTransfer() {
50+
if (!hasDryRunSupport('AssetHubPaseo')) {
51+
console.log('Dry run is not supported on AssetHubPaseo.');
52+
return;
53+
}
54+
55+
const tx = await Builder()
56+
.from('AssetHubPaseo')
57+
.to('PeoplePaseo')
58+
.currency({
59+
symbol: 'PAS',
60+
amount: 10n * PAS_UNITS,
61+
})
62+
.address(RECIPIENT_ADDRESS)
63+
.senderAddress(SENDER_ADDRESS)
64+
.dryRun();
65+
66+
console.log(inspect(tx, { colors: true, depth: null }));
67+
process.exit(0);
68+
}
69+
70+
dryRunTransfer();
71+
72+
async function verifyED() {
73+
const isValid = await Builder()
74+
.from('AssetHubPaseo')
75+
.to('PeoplePaseo')
76+
.currency({
77+
symbol: 'PAS',
78+
amount: 10n * PAS_UNITS,
79+
})
80+
.address(RECIPIENT_ADDRESS)
81+
.senderAddress(SENDER_ADDRESS)
82+
.verifyEdOnDestination();
83+
84+
console.log(`ED verification ${isValid ? 'successful' : 'failed'}.`);
85+
process.exit(0);
86+
}
87+
88+
verifyED();
89+
90+
async function XcmTransferInfo() {
91+
const info = await Builder()
92+
.from('AssetHubPaseo')
93+
.to('PeoplePaseo')
94+
.currency({
95+
symbol: 'PAS',
96+
amount: 10n * PAS_UNITS,
97+
})
98+
.address(RECIPIENT_ADDRESS)
99+
.senderAddress(SENDER_ADDRESS)
100+
.getTransferInfo();
101+
102+
console.log('Transfer Info:', info);
103+
process.exit(0);
104+
}
105+
106+
XcmTransferInfo();
107+
108+
transfer();

0 commit comments

Comments
 (0)