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
+27-14Lines changed: 27 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,18 @@ 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
-
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}.
19
+
This guide demonstrates how to interact with the XCM precompile through Solidity smart contracts using [Remix IDE](/develop/smart-contracts/dev-environments/remix){target=\_blank}.
20
+
21
+
!!!note
22
+
The XCM precompile provides the barebones XCM functionality. While it provides a lot of flexibility, it doesn't provide abstractions to hide away XCM details. These have to be built on top.
20
23
21
24
## Precompile Interface
22
25
@@ -33,7 +36,7 @@ The interface defines a `Weight` struct that represents the computational cost o
33
36
34
37
All XCM messages must be encoded using the [SCALE codec](/polkadot-protocol/parachain-basics/data-encoding/#data-encoding){target=\_blank}, Polkadot's standard serialization format.
35
38
36
-
For further information, check the [`precompiles/IXCM.sol`](https://github.com/paritytech/polkadot-sdk/blob/cb629d46ebf00aa65624013a61f9c69ebf02b0b4/polkadot/xcm/pallet-xcm/src/precompiles/IXcm.sol){target=\_blank} file present in the `pallet-xcm`.
39
+
For further information, check the [`precompiles/IXCM.sol`](https://github.com/paritytech/polkadot-sdk/blob/cb629d46ebf00aa65624013a61f9c69ebf02b0b4/polkadot/xcm/pallet-xcm/src/precompiles/IXcm.sol){target=\_blank} file present in `pallet-xcm`.
37
40
38
41
## Interact with the XCM Precompile
39
42
@@ -55,6 +58,8 @@ To interact with the XCM precompile, you can use the precompile interface direct
The main entrypoint of the precompile is the `execute` function. However, it's necessary to first call `weighMessage` to fill in the required parameters.
62
+
58
63
### Weigh a Message
59
64
60
65
The `weighMessage` function estimates the computational cost required to execute an XCM message. This estimate is crucial for understanding the resources needed before actually executing or sending a message.
@@ -80,24 +85,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.
88
+
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
89
85
90
### Execute a Message
86
91
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.
92
+
The `execute` function runs an XCM message locally using the caller's origin.
93
+
This function is the main entrypoint to cross-chain interactions.
88
94
89
95
Follow these steps to execute a message:
90
96
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:
97
+
1. Call `weighMessage` with your message to get the required weight.
98
+
2.Pass the same message bytes and the weight obtained from the previous step to `execute`.
99
+
For example, using the same message from the weighing example, you would call `execute` with:
94
100
95
101
- `message`: The encoded XCM message bytes.
96
-
-`weight`: The `Weight` struct returned from `callWeighMessage`.
102
+
- `weight`: The `Weight` struct returned from `weighMessage`.
97
103
98
104
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
105
100
-
5. Click on the **Transact** button to execute the xcm message:
106
+
3. On Remix, click on the **Transact** button to execute the XCM message:
@@ -109,13 +115,13 @@ Additionally, you can verify that the execution of this specific message was suc
109
115
110
116
### Send a Message
111
117
112
-
The `send` function is responsible for transmitting an XCM message to a destination chain, enabling essential cross-chain communication.
118
+
While most cross-chain operations can be performed via `execute`, `send` is sometimes necessary, for example, when opening HRMP channels.
113
119
114
120
To send a message:
115
121
116
122
1. Prepare your destination location encoded in XCM format.
117
123
2. Prepare your XCM message (similar to the execute example).
118
-
3. Call `callXcmSend` with both parameters.
124
+
3. Call `send` with both parameters.
119
125
120
126
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.
121
127
@@ -129,4 +135,11 @@ Whether you're building DeFi protocols, governance systems, or any application r
129
135
130
136
## Conclusion
131
137
132
-
The XCM precompile provides a powerful interface for cross-chain interactions within the Polkadot ecosystem. By understanding how to properly encode messages, estimate weights, and execute or send XCM instructions, developers can build sophisticated cross-chain applications that leverage the full potential of Polkadot's interoperability features.
138
+
The XCM precompile provides a simple yet powerful interface for cross-chain interactions within the Polkadot ecosystem and beyond.
139
+
By building and executing XCM programs, developers can build cross-chain applications that leverage the full potential of Polkadot's interoperability features.
140
+
141
+
## Next steps
142
+
143
+
Head to the Polkadot Hub TestNet and start playing around with the precompile using Hardhat or Foundry.
144
+
145
+
You can use PAPI to build XCM programs and test them with Chopsticks.
0 commit comments