Skip to content

Commit 3657cd2

Browse files
committed
Merge branch 'master' into format-wallets
2 parents 0bbfbbc + 8a1dbb8 commit 3657cd2

File tree

6 files changed

+178
-95
lines changed

6 files changed

+178
-95
lines changed

develop/smart-contracts/precompiles/xcm-precompile.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ categories: Smart Contracts
88

99
## Introduction
1010

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.
1212

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:
1414

1515
- **`execute`**: for local XCM execution
1616
- **`send`**: for cross-chain message transmission
1717
- **`weighMessage`**: for cost estimation
1818

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.
2023

2124
## Precompile Interface
2225

@@ -33,7 +36,7 @@ The interface defines a `Weight` struct that represents the computational cost o
3336

3437
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.
3538

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`.
3740

3841
## Interact with the XCM Precompile
3942

@@ -55,6 +58,8 @@ To interact with the XCM precompile, you can use the precompile interface direct
5558

5659
![](/images/develop/smart-contracts/precompiles/xcm-precompile/xcm-precompile-03.webp)
5760

61+
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+
5863
### Weigh a Message
5964

6065
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
8085
![](/images/develop/smart-contracts/precompiles/xcm-precompile/xcm-precompile-05.webp)
8186

8287
!!!note
83-
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.
8489

8590
### Execute a Message
8691

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.
8894

8995
Follow these steps to execute a message:
9096

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:
94100

95101
- `message`: The encoded XCM message bytes.
96-
- `weight`: The `Weight` struct returned from `callWeighMessage`.
102+
- `weight`: The `Weight` struct returned from `weighMessage`.
97103

98104
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.
99105

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:
101107

102108
![](/images/develop/smart-contracts/precompiles/xcm-precompile/xcm-precompile-06.webp)
103109

@@ -109,13 +115,13 @@ Additionally, you can verify that the execution of this specific message was suc
109115

110116
### Send a Message
111117

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.
113119

114120
To send a message:
115121

116122
1. Prepare your destination location encoded in XCM format.
117123
2. Prepare your XCM message (similar to the execute example).
118-
3. Call `callXcmSend` with both parameters.
124+
3. Call `send` with both parameters.
119125

120126
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.
121127

@@ -129,4 +135,11 @@ Whether you're building DeFi protocols, governance systems, or any application r
129135

130136
## Conclusion
131137

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

Comments
 (0)