Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Substrate.io Migration] Tutorials -> Build a Parachain -> Transfer Assets with XCM #30

Merged
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
1a523ef
fix: adding prepare substrate relay chain
nhussein11 Sep 9, 2024
a59e5e3
fiox: formatting error
nhussein11 Sep 9, 2024
d5cc084
fix: description
nhussein11 Sep 9, 2024
5e7a4dc
fix: paraphrasing
nhussein11 Sep 9, 2024
2413eec
fix: vale warning
nhussein11 Sep 9, 2024
291a833
fix: formatting
nhussein11 Sep 9, 2024
3b73da1
fix: adding conclusion to the tutorial
nhussein11 Sep 9, 2024
fabc617
fix: formatting
nhussein11 Sep 10, 2024
5316122
fix: formatting
nhussein11 Sep 10, 2024
763f598
git: adding intro and build the parachain template section
nhussein11 Sep 10, 2024
d27184f
fix: adding wip
nhussein11 Sep 10, 2024
ff83f15
fix: updating prepare relay chain output and commands
nhussein11 Sep 10, 2024
339514f
Merge branch 'nhussein11/tutorials-substrate-prepare-relay-chain' int…
nhussein11 Sep 10, 2024
907bff6
fix: adding build a parachain complete process
nhussein11 Sep 10, 2024
75d518f
fix: vale suggestion
nhussein11 Sep 10, 2024
77509c5
fix: adding acquire a slot on testnet wip
nhussein11 Sep 11, 2024
a83ddde
fix: adding admin account example
nhussein11 Sep 11, 2024
a956e4a
fix: typos
nhussein11 Sep 11, 2024
2a7f3b3
fix: typo
nhussein11 Sep 11, 2024
010a96d
fix: typo
nhussein11 Sep 11, 2024
4d2296c
fix: formatting
nhussein11 Sep 11, 2024
5f7a28c
fix: formatting
nhussein11 Sep 11, 2024
213814e
fix: typo and adding abs route to build a local blockchain tutorial
nhussein11 Sep 11, 2024
1286b44
fix: paraphrasing
nhussein11 Sep 11, 2024
4f2a152
fix: updating deprecated route
nhussein11 Sep 11, 2024
f8b1fa8
fix: paraphrasing
nhussein11 Sep 11, 2024
1cb5f77
fix: formatting
nhussein11 Sep 11, 2024
5274116
fix: chain specs decoupled from substrate website
nhussein11 Sep 11, 2024
1c6aa95
fix: wip trransfer assets
nhussein11 Sep 13, 2024
6bfe5e4
Update tutorials/polkadot-sdk/build-a-parachain/prepare-relay-chain.md
nhussein11 Sep 23, 2024
6446b16
fix: typo
nhussein11 Sep 23, 2024
aa08eca
fix: removing redundant commands on terminal elements
nhussein11 Sep 23, 2024
8acc357
fix: adding disclaimer for chain spec generation
nhussein11 Sep 23, 2024
231eafe
fix: removing redundant commands on terminal elements
nhussein11 Sep 23, 2024
1cac723
fix: removing unnecessary info
nhussein11 Sep 23, 2024
38ab69e
fix: addin small clarification about sudo txs
nhussein11 Sep 23, 2024
357bd72
fix: clarification about sudo changes
nhussein11 Sep 23, 2024
7a21a64
Update tutorials/polkadot-sdk/build-a-parachain/connect-a-parachain.md
nhussein11 Sep 23, 2024
bd8ff69
fix: adding missing terminal output
nhussein11 Sep 23, 2024
df3357c
fix: adding image to register with the local relay chain process, step 6
nhussein11 Sep 23, 2024
f463234
Apply suggestions from code review
nhussein11 Sep 24, 2024
ac7f71a
fix: moving terminal outputs to code snippets
nhussein11 Sep 24, 2024
1bd5b34
Merge branch 'master' into nhussein11/tutorials-substrate-prepare-rel…
nhussein11 Sep 24, 2024
daadd83
Merge branch 'nhussein11/tutorials-substrate-prepare-relay-chain' int…
nhussein11 Sep 24, 2024
6516f69
fix: adding clarification over resetting bc state
nhussein11 Sep 24, 2024
d4f68e4
fix: adding hook to further tutorials
nhussein11 Sep 25, 2024
f72452c
fix: moving transfer assets with xcm to different section
nhussein11 Sep 25, 2024
32a19a1
fix: adding confirmation after assets transfer
nhussein11 Sep 25, 2024
47ffedd
fix: updating image 6
nhussein11 Sep 25, 2024
faf17ec
Update develop/parachain-devs/interoperability/transfer-assets-with-x…
nhussein11 Sep 26, 2024
b660586
fix: updating zombie workaround name reference
nhussein11 Sep 26, 2024
467acb2
fix: updating prerequisites
nhussein11 Sep 26, 2024
3acdca4
fix: updating title for configure xcm instructions
nhussein11 Sep 26, 2024
40fc95e
fix: updating define the xcm destination for the message intro
nhussein11 Sep 26, 2024
a906327
fix: update image 3
nhussein11 Sep 26, 2024
de30612
fix: applying indent
nhussein11 Sep 26, 2024
3134b80
fix: paraphrasing
nhussein11 Sep 26, 2024
4e8e48e
Update develop/parachain-devs/interoperability/transfer-assets-with-x…
nhussein11 Sep 26, 2024
bbd0146
fix: removing unnecessary note
nhussein11 Sep 26, 2024
0f14b83
fix: paraphrasing
nhussein11 Sep 26, 2024
8bc01ed
fix: re-factoring and adding limited teleport asset explanation
nhussein11 Sep 30, 2024
08bcefc
fix: adding reserve transfer asset procedure
nhussein11 Sep 30, 2024
a0b694f
fix: updating imgs routes
nhussein11 Sep 30, 2024
e49ca6f
Merge branch 'nhussein11/tutorials-substrate-connect-a-parachain' int…
nhussein11 Sep 30, 2024
08029d1
Merge branch 'master' into nhussein11/tutorials-substrate-transfer-as…
nhussein11 Sep 30, 2024
d9d9cdb
fix: updating docs
nhussein11 Oct 2, 2024
5570f98
fix: period at the end of list item
nhussein11 Oct 2, 2024
12644e8
Merge remote-tracking branch 'origin/master' into nhussein11/tutorial…
eshaben Oct 3, 2024
5dd28fb
add paseo images back
eshaben Oct 3, 2024
b6bec51
add four spaces for json snippets
eshaben Oct 3, 2024
f0b2f6d
Apply suggestions from code review
nhussein11 Oct 4, 2024
1f7f621
Apply suggestions from code review
nhussein11 Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div id="termynal" data-termynal>
<span>2024-09-09 13:49:58 Parity Polkadot</span>
<br>
<span>2024-09-09 13:49:58 ✌️ version 1.15.2-d6f482d5593</span>
<br>
<span>2024-09-09 13:49:58 ❤️ by Parity Technologies <[email protected]>, 2017-2024</span>
<br>
<span>2024-09-09 13:49:58 📋 Chain specification: Rococo Local Testnet</span>
<br>
<span>2024-09-09 13:49:58 🏷 Node name: Alice</span>
<br>
<span>2024-09-09 13:49:58 👤 Role: AUTHORITY</span>
<br>
<span>2024-09-09 13:49:58 💾 Database: RocksDb at /tmp/relay/alice/chains/rococo_local_testnet/db/full<span>
<br>
<span>2024-09-09 13:49:59 🏷 Local node identity is: 12D3KooWG393uX82rR3QgDkZpb7U8StzuRx9BQUXCvWsP1ctgygp</span>
<br>
<span>2024-09-09 13:49:59 Running libp2p network backend</span>
<br>
<span>...</span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div id="termynal" data-termynal>
<span>...</span>
<br>
<span>2024-09-10 13:29:38 🏆 Imported #55 (0xad6a…567c → 0xecae…ad12)<span>
<br>
<span>2024-09-10 13:29:38 💤 Idle (1 peers), best: #55 (0xecae…ad12), finalized #0 (0x1cac…618d), ⬇ 2.0kiB/s ⬆ 1.6kiB/s</span>
<br>
<span>...</span>
</div>
1 change: 1 addition & 0 deletions develop/parachain-devs/interoperability/.pages
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
title: Interoperability
nav:
- index.md
- 'Transfer Assets with XCM': transfer-assets-with-xcm.md
- hrmp-channels
156 changes: 156 additions & 0 deletions develop/parachain-devs/interoperability/transfer-assets-with-xcm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
---
title: Transfer Assets with XCM
description: This tutorial will guide you through the process of transferring assets between parachains using Cross-Chain Message (XCM) instructions.
nhussein11 marked this conversation as resolved.
Show resolved Hide resolved
---

# Transfer Assets with XCM

## Introduction

In the tutorial on [Open Message Passing Channels](TODO:update-path){target=\_blank} you learned how to establish a two-way communication channel between chains by sending messages to the relay chain. You can apply a similar approach to send messages that enable a local chain to manage an account on a remote chain. This tutorial will teach you how to transfer assets between chains using Cross-Chain Message (XCM) instructions.
nhussein11 marked this conversation as resolved.
Show resolved Hide resolved

To transfer assets between two chains, you have the options of [Teleporting Assets](https://wiki.polkadot.network/docs/learn-teleport){target=\_blank} or performing a [Reserve Asset Transfer](https://wiki.polkadot.network/docs/learn/xcm/journey/transfers-reserve){target=\_blank}. This tutorial will cover both methods.

## Prerequisites

Before you begin, verify the following:

- You have a relay chain and a parachain running to test the XCM instructions
- You have opened the message passing channel to allow communication between the two chains

## Teleporting Assets

Asset teleportation enables the transfer of digital assets, including fungible and non-fungible tokens, across different parachains. This process allows the transferred assets to function as if they were native to the receiving chain. To simulate the teleportation of assets, this tutorial showcases the transfer of fungible tokens between the Polkadot relay chain and the Asset Hub system parachain.
nhussein11 marked this conversation as resolved.
Show resolved Hide resolved

To replicate the scenario, this guide uses [Chopsticks](https://github.com/AcalaNetwork/chopsticks){target=\_blank} to interact with the relay chain and the Asset Hub parachain. To setup the same environment, run the following command:
nhussein11 marked this conversation as resolved.
Show resolved Hide resolved

```bash
chopsticks xcm \
--r polkadot \
--p polkadot-asset-hub
```

The command above initializes the Chopsticks tool to interact with the Polkadot relay chain and the Asset Hub parachain. You can replace the `polkadot` and `polkadot-asset-hub` parameters with the actual names of the chains you want to interact with. For further details on the Chopsticks tool, refer to the [Chopsticks documentation](TODO:update-path){target=\_blank}.

To teleport assets between the two chains, follow these steps:

1. Navigate to the **Extrinsics** tab of the relay chain in the Polkadot.js Apps interface
1. Select the **Developer** tab from the sidebar
2. Choose the **Extrinsics** option

![](/images/develop/parachain-devs/interoperability/transfer-assets-with-xcm/transfer-assets-with-xcm-1.webp)

2. Select the **xcmPallet** and the **limitedTeleportAssets** extrinsic
1. Choose the **xcmPallet** from the list of pallets
2. Select the **limitedTeleportAssets** extrinsic from the extrinsics available

![](/images/develop/parachain-devs/interoperability/transfer-assets-with-xcm/transfer-assets-with-xcm-2.webp)

3. Fill in the required parameters for the extrinsic
1. Enter the **dest** multilocation of the destination chain. In this case, since the destination chain is Asset Hub (ID `1000`), its Multilocation from the Relay Chain perspective is:
nhussein11 marked this conversation as resolved.
Show resolved Hide resolved
nhussein11 marked this conversation as resolved.
Show resolved Hide resolved
```json
{
"parent": 0,
"interior": {
"X1": {
"Parachain": 1000
}
}
}
```
2. Specify the **beneficiary** to receive the assets. The beneficiary should be specified from the perspective of the destination chain. This tutorial uses the account `14BPeNxwQUBCDkZhAZMBTCD4ZbJ3VN4AdvDaUwDk8GxQbPbD` on the Asset Hub parachain, so the beneficiary MultiLocation is:
nhussein11 marked this conversation as resolved.
Show resolved Hide resolved
```json
{
"parent": 0,
"interior": {
"X1": {
"AccountId32": "14BPeNxwQUBCDkZhAZMBTCD4ZbJ3VN4AdvDaUwDk8GxQbPbD"
}
}
}
```
3. Define the **assets** to teleport. This fields specifies the Multilocation fo the asset and the fungibility of the asset
nhussein11 marked this conversation as resolved.
Show resolved Hide resolved
4. Provide the **feeAssetItem** to define the asset to be used as the fee for the teleportation
5. Specify the **weightLimit** as the maximum weight to be used for the extrinsic execution
6. Click on **Submit Transaction** to execute the extrinsic

![](/images/develop/parachain-devs/interoperability/transfer-assets-with-xcm/transfer-assets-with-xcm-3.webp)

4. After submitting the transaction, you can check the status of the teleportation by navigating to the **Events** tab of the relay chain in the Polkadot.js Apps interface. If the XCM message is successfully sent, you will see the event `xcmPallet.Sent` in the list of events

![](/images/develop/parachain-devs/interoperability/transfer-assets-with-xcm/transfer-assets-with-xcm-4.webp)

5. To verify the teleportation on the Asset Hub parachain, navigate to the **Events** section. You should see two events, **`messageQueu.Processed`** and **`balances.Transfer`**

![](/images/develop/parachain-devs/interoperability/transfer-assets-with-xcm/transfer-assets-with-xcm-5.webp)

These events indicate that the teleportation of assets was successful. You can now verify the balance of the beneficiary account on the Asset Hub parachain to confirm the transfer.
nhussein11 marked this conversation as resolved.
Show resolved Hide resolved

## Reserve Asset Transfer

When consensus systems lack sufficient trust for direct asset teleportation, they can leverage a trusted third-party reserve (such as Asset Hub) to hold the actual assets. To track ownership of these reserve-held assets, both the source and destination chains typically create derivative tokens. Each chain maintains a dedicated account, known as a sovereign account, on the reserve to manage its asset holdings.
nhussein11 marked this conversation as resolved.
Show resolved Hide resolved

To simulate a reserve asset transfer, this tutorial demonstrates that funcionality between the Polkadot relay chain and the Astar parachain. This tutorial uses Chopstick to simulate the interaction between the two chains. To set up the environment, run the following command:

```bash
nhussein11 marked this conversation as resolved.
Show resolved Hide resolved
chopsticks xcm \
--r polkadot \
--p polkadot-asset-hub \
nhussein11 marked this conversation as resolved.
Show resolved Hide resolved
--p astar
```

The command above initializes the Chopsticks tool to interact with the Polkadot relay chain, the Asset Hub parachain, and the Astar parachain. You can replace the `polkadot`, `polkadot-asset-hub`, and `astar` parameters with the actual names of the chains you want to interact with. For further details on the Chopsticks tool, refer to the [Chopsticks documentation](TODO:update-path){target=\_blank}.

To do a reserve asset transfer between the two chains, follow these steps:

1. Navigate to the **Extrinsics** tab of the relay chain in the Polkadot.js Apps interface
1. Select the **Developer** tab from the sidebar
2. Choose the **Extrinsics** option

![](/images/develop/parachain-devs/interoperability/transfer-assets-with-xcm/transfer-assets-with-xcm-1.webp)

2. Select the **xcmPallet** and the **limitedReservedTransferAssets** extrinsic
1. Choose the **xcmPallet** from the list of pallets
2. Select the **limitedReserveTransferAssets** extrinsic from the extrinsics available

![](/images/develop/parachain-devs/interoperability/transfer-assets-with-xcm/transfer-assets-with-xcm-6.webp)

3. Fill in the required parameters for the extrinsic
1. Enter the **dest** multilocation of the destination chain. In this case, since the destination chain is the Astar parachain (ID `2006`), its Multilocation from the Relay Chain perspective is:
nhussein11 marked this conversation as resolved.
Show resolved Hide resolved
```json
{
"parent": 0,
"interior": {
"X1": {
"Parachain": 2006
}
}
}
```
2. Specify the **beneficiary** to receive the assets. The beneficiary should be specified from the perspective of the destination chain. This tutorial uses the account `Z7gwLfxKvYq13b1hDkJLhYBo21WmHCmaczEZMSFSYvr16Ao` on the Astar parachain, so the beneficiary MultiLocation is:
nhussein11 marked this conversation as resolved.
Show resolved Hide resolved
```json
{
"parent": 0,
"interior": {
"X1": {
"AccountId32": "Z7gwLfxKvYq13b1hDkJLhYBo21WmHCmaczEZMSFSYvr16Ao"
}
}
}
```
3. Define the **assets** to teleport. This fields specifies the Multilocation fo the asset and the fungibility of the asset
nhussein11 marked this conversation as resolved.
Show resolved Hide resolved
4. Provide the **feeAssetItem** to define the asset to be used as the fee for the teleportation
5. Specify the **weightLimit** as the maximum weight to be used for the extrinsic execution
6. Click on **Submit Transaction** to execute the extrinsic

![](/images/develop/parachain-devs/interoperability/transfer-assets-with-xcm/transfer-assets-with-xcm-7.webp)

4. After submitting the transaction, you can check the status of the teleportation by navigating to the **Events** tab of the relay chain in the Polkadot.js Apps interface. If the XCM message is successfully sent, you will see the event **`xcmPallet.Sent`** in the list of events

![](/images/develop/parachain-devs/interoperability/transfer-assets-with-xcm/transfer-assets-with-xcm-8.webp)

5. To verify the teleportation on the Asset Hub parachain, navigate to the **Events** section. You should see two events, **`messageQueu.Processed`**, **`balances.Issued`** and **`balances.Transfer`**

![](/images/develop/parachain-devs/interoperability/transfer-assets-with-xcm/transfer-assets-with-xcm-9.webp)

These events indicate that the reserve asset transfer was successful. You can now verify the balance of the beneficiary account on the Astar parachain to confirm the transfer.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading