You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: develop/smart-contracts/precompiles/xcm-precompile.md
+15-11Lines changed: 15 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,16 +8,19 @@ categories: Smart Contracts
8
8
9
9
## Introduction
10
10
11
-
The [XCM (Cross-Consensus Message)](/develop/interoperability/intro-to-xcm){target=\_blank} precompile enables Polkadot Hub developers to access XCM functionality directly from their smart contracts, sending cross-chain messages, executing XCM instructions locally, and estimating execution costs—all through a standardized Solidity interface.
11
+
The [XCM (Cross-Consensus Message)](/develop/interoperability/intro-to-xcm){target=\_blank} precompile enables Polkadot Hub developers to access XCM functionality directly from their smart contracts using a Solidity interface.
12
12
13
-
Located at the fixed address `0x00000000000000000000000000000000000a0000`, the XCM precompile offers three primary functions:
13
+
Located at the fixed address `0x00000000000000000000000000000000000a0000`, the XCM precompile offers three primary functions:
14
14
15
15
-**`execute`**: for local XCM execution
16
16
-**`send`**: for cross-chain message transmission
17
17
-**`weighMessage`**: for cost estimation
18
18
19
19
This guide demonstrates how to interact with the XCM precompile through Solidity smart contracts using [Remix IDE](/develop/smart-contracts/dev-environments/remix.md){target=\_blank}.
20
20
21
+
!!!note
22
+
The XCM precompile is very barebones. It's the most flexible but as such, doesn't provide abstractions to hide away XCM details. These have to be built on top.
23
+
21
24
## Precompile Interface
22
25
23
26
The XCM precompile implements the `IXcm` interface, which defines the structure for interacting with XCM functionality. The source code for the interface is as follows:
@@ -80,24 +83,25 @@ The function returns a `Weight` struct containing `refTime` and `proofSize` valu
To interact with Polkadot Hub TestNet, visit this [gist](https://gist.github.com/franciscoaguirre/a6dea0c55e81faba65bedf700033a1a2){target=\_blank}, which provides examples of how to craft XCM messages for different purposes.
86
+
You can find many more examples of XCMs in this [gist](https://gist.github.com/franciscoaguirre/a6dea0c55e81faba65bedf700033a1a2){target=\_blank} which connects to the Polkadot Hub testnet.
84
87
85
88
### Execute a Message
86
89
87
-
The `execute` function runs an XCM message locally using the caller's origin. This function helps execute XCM instructions that don't require cross-chain communication.
90
+
The `execute` function runs an XCM message locally using the caller's origin.
91
+
This function is the main entrypoint to cross-chain interactions.
88
92
89
93
Follow these steps to execute a message:
90
94
91
-
1. Call `callWeighMessage` with your XCM message to get the required weight.
92
-
2.Use the returned weight values when calling `callXcmExecute`.
93
-
3. Pass the same XCM message bytes and the weight obtained from the previous step. For example, using the same message from the weighing example, you would call `callXcmExecute` with:
95
+
1. Call `weighMessage` with your message to get the required weight.
96
+
2.Pass the same message bytes and the weight obtained from the previous step to `execute`.
97
+
For example, using the same message from the weighing example, you would call `execute` with:
94
98
95
99
- `message`: The encoded XCM message bytes.
96
-
-`weight`: The `Weight` struct returned from `callWeighMessage`.
100
+
- `weight`: The `Weight` struct returned from `weighMessage`.
97
101
98
102
You can use the [papi console](https://dev.papi.how/extrinsics#networkId=localhost&endpoint=wss%3A%2F%2Ftestnet-passet-hub.polkadot.io&data=0x1f03050c000401000003008c86471301000003008c8647000d010101000000010100368e8759910dab756d344995f1d3c79374ca8f70066d3a709e48029f6bf0ee7e0750c61e2901daad0600){target=\_blank} to examine the complete extrinsic structure for this operation.
99
103
100
-
5. Click on the **Transact** button to execute the xcm message:
104
+
3. On Remix, click on the **Transact** button to execute the xcm message:
@@ -109,13 +113,13 @@ Additionally, you can verify that the execution of this specific message was suc
109
113
110
114
### Send a Message
111
115
112
-
The `send` function is responsible for transmitting an XCM message to a destination chain, enabling essential cross-chain communication.
116
+
While most cross-chain operations can be done via `execute`, sometimes `send` is needed, for example, when opening HRMP channels.
113
117
114
118
To send a message:
115
119
116
120
1. Prepare your destination location encoded in XCM format.
117
121
2. Prepare your XCM message (similar to the execute example).
118
-
3. Call `callXcmSend` with both parameters.
122
+
3. Call `send` with both parameters.
119
123
120
124
The destination parameter must be encoded according to XCM's location format, specifying the target parachain or consensus system. The message parameter contains the XCM instructions to be executed on the destination chain.
The [XCM (Cross-Consensus Message)](/develop/interoperability/intro-to-xcm){target=\_blank} precompile enables Polkadot Hub developers to access XCM functionality directly from their smart contracts, sending cross-chain messages, executing XCM instructions locally, and estimating execution costs—all through a standardized Solidity interface.
12482
+
The [XCM (Cross-Consensus Message)](/develop/interoperability/intro-to-xcm){target=\_blank} precompile enables Polkadot Hub developers to access XCM functionality directly from their smart contracts using a Solidity interface.
12483
12483
12484
-
Located at the fixed address `0x00000000000000000000000000000000000a0000`, the XCM precompile offers three primary functions:
12484
+
Located at the fixed address `0x00000000000000000000000000000000000a0000`, the XCM precompile offers three primary functions:
12485
12485
12486
12486
- **`execute`**: for local XCM execution
12487
12487
- **`send`**: for cross-chain message transmission
12488
12488
- **`weighMessage`**: for cost estimation
12489
12489
12490
12490
This guide demonstrates how to interact with the XCM precompile through Solidity smart contracts using [Remix IDE](/develop/smart-contracts/dev-environments/remix.md){target=\_blank}.
12491
12491
12492
+
!!!note
12493
+
The XCM precompile is very barebones. It's the most flexible but as such, doesn't provide abstractions to hide away XCM details. These have to be built on top.
12494
+
12492
12495
## Precompile Interface
12493
12496
12494
12497
The XCM precompile implements the `IXcm` interface, which defines the structure for interacting with XCM functionality. The source code for the interface is as follows:
@@ -12591,24 +12594,25 @@ The function returns a `Weight` struct containing `refTime` and `proofSize` valu
To interact with Polkadot Hub TestNet, visit this [gist](https://gist.github.com/franciscoaguirre/a6dea0c55e81faba65bedf700033a1a2){target=\_blank}, which provides examples of how to craft XCM messages for different purposes.
12597
+
You can find many more examples of XCMs in this [gist](https://gist.github.com/franciscoaguirre/a6dea0c55e81faba65bedf700033a1a2){target=\_blank} which connects to the Polkadot Hub testnet.
12595
12598
12596
12599
### Execute a Message
12597
12600
12598
-
The `execute` function runs an XCM message locally using the caller's origin. This function helps execute XCM instructions that don't require cross-chain communication.
12601
+
The `execute` function runs an XCM message locally using the caller's origin.
12602
+
This function is the main entrypoint to cross-chain interactions.
12599
12603
12600
12604
Follow these steps to execute a message:
12601
12605
12602
-
1. Call `callWeighMessage` with your XCM message to get the required weight.
12603
-
2. Use the returned weight values when calling `callXcmExecute`.
12604
-
3. Pass the same XCM message bytes and the weight obtained from the previous step. For example, using the same message from the weighing example, you would call `callXcmExecute` with:
12606
+
1. Call `weighMessage` with your message to get the required weight.
12607
+
2. Pass the same message bytes and the weight obtained from the previous step to `execute`.
12608
+
For example, using the same message from the weighing example, you would call `execute` with:
12605
12609
12606
12610
- `message`: The encoded XCM message bytes.
12607
-
- `weight`: The `Weight` struct returned from `callWeighMessage`.
12611
+
- `weight`: The `Weight` struct returned from `weighMessage`.
12608
12612
12609
12613
You can use the [papi console](https://dev.papi.how/extrinsics#networkId=localhost&endpoint=wss%3A%2F%2Ftestnet-passet-hub.polkadot.io&data=0x1f03050c000401000003008c86471301000003008c8647000d010101000000010100368e8759910dab756d344995f1d3c79374ca8f70066d3a709e48029f6bf0ee7e0750c61e2901daad0600){target=\_blank} to examine the complete extrinsic structure for this operation.
12610
12614
12611
-
5. Click on the **Transact** button to execute the xcm message:
12615
+
3. On Remix, click on the **Transact** button to execute the xcm message:
@@ -12620,13 +12624,13 @@ Additionally, you can verify that the execution of this specific message was suc
12620
12624
12621
12625
### Send a Message
12622
12626
12623
-
The `send` function is responsible for transmitting an XCM message to a destination chain, enabling essential cross-chain communication.
12627
+
While most cross-chain operations can be done via `execute`, sometimes `send` is needed, for example, when opening HRMP channels.
12624
12628
12625
12629
To send a message:
12626
12630
12627
12631
1. Prepare your destination location encoded in XCM format.
12628
12632
2. Prepare your XCM message (similar to the execute example).
12629
-
3. Call `callXcmSend` with both parameters.
12633
+
3. Call `send` with both parameters.
12630
12634
12631
12635
The destination parameter must be encoded according to XCM's location format, specifying the target parachain or consensus system. The message parameter contains the XCM instructions to be executed on the destination chain.
0 commit comments