Skip to content

Commit aed79a1

Browse files
Apply suggestions from code review
Co-authored-by: Dawn Kelly <[email protected]>
1 parent ee26a84 commit aed79a1

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

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

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,48 @@
11
---
22
title: Interact with the XCM Precompile
3-
description: Learn how to use the XCM precompile to send cross-chain messages, execute XCM instructions, and estimate costs from your smart contracts
3+
description: Learn how to use the XCM precompile to send cross-chain messages, execute XCM instructions, and estimate costs from your smart contracts.
4+
categories: Smart Contracts
45
---
56

67
# XCM Precompile
78

89
## Introduction
910

10-
The XCM (Cross-Consensus Message) precompile enables Polkadot Hub developers to access XCM functionality directly from their smart contracts. This precompile enables contracts to send cross-chain messages, execute XCM instructions locally, and estimate execution costs—all through a standardized Solidity interface.
11+
The XCM (Cross-Consensus Message) 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.
1112

12-
Located at the fixed address `0x00000000000000000000000000000000000a0000`, the XCM precompile offers three primary functions: `execute` for local XCM execution, `send` for cross-chain message transmission, and `weighMessage` for cost estimation. 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}.
13+
Located at the fixed address `0x00000000000000000000000000000000000a0000`, the XCM precompile offers three primary functions:
14+
15+
- **`execute`**: for local XCM execution
16+
-**`send`**: for cross-chain message transmission
17+
- **`weighMessage`**: for cost estimation
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}.
1320

1421
## Precompile Interface
1522

16-
The XCM precompile implements the `IXcm` interface, which defines the structure for interacting with XCM functionality:
23+
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:
1724

1825
```solidity title="IXcm.sol"
1926
--8<-- "https://raw.githubusercontent.com/paritytech/polkadot-sdk/cb629d46ebf00aa65624013a61f9c69ebf02b0b4/polkadot/xcm/pallet-xcm/src/precompiles/IXcm.sol"
2027
```
2128

22-
The interface defines a `Weight` struct that represents the computational cost of XCM operations. Weight has two components: `refTime` (computational time on reference hardware) and `proofSize` (size of the proof needed for execution). 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.
29+
The interface defines a `Weight` struct that represents the computational cost of XCM operations. Weight has two components: `refTime` (computational time on reference hardware) and `proofSize` (the size of the proof required for execution). 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.
2330

2431
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`.
2532

2633
## Interact with the XCM Precompile
2734

2835
To interact with the XCM precompile, you can use the precompile interface directly in Remix IDE:
2936

30-
1. Create a new file called `IXcm.sol` in Remix
31-
2. Copy and paste the `IXcm` interface code into the file
32-
3. Compile the interface
37+
1. Create a new file called `IXcm.sol` in Remix.
38+
2. Copy and paste the `IXcm` interface code into the file.
39+
3. Compile the interface by selecting the button or using **Ctrl +S** keys:
3340

3441
![](/images/develop/smart-contracts/precompiles/xcm-precompile/xcm-precompile-01.webp)
3542

36-
4. In the Deploy & Run Transactions tab, select the `IXcm` interface from the contract dropdown
37-
5. Enter the precompile address `0x00000000000000000000000000000000000a0000` in the **At Address** input field
38-
6. Click "At Address" to connect to the precompile
43+
4. In the Deploy & Run Transactions tab, select the `IXcm` interface from the contract dropdown.
44+
5. Enter the precompile address `0x00000000000000000000000000000000000a0000` in the **At Address** input field.
45+
6. Click "At Address" to connect to the precompile.
3946

4047
![](/images/develop/smart-contracts/precompiles/xcm-precompile/xcm-precompile-02.webp)
4148

@@ -45,7 +52,7 @@ Once connected, you can directly interact with the XCM precompile's functions (`
4552

4653
### Weight a Message
4754

48-
The `weighMessage` function estimates the computational cost required to execute an XCM message. This is crucial for understanding the resources needed before actually executing or sending a message.
55+
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.
4956

5057
To test this functionality in Remix, you can call `callWeighMessage` with a SCALE-encoded XCM message. For example, for testing, you can use the following encoded XCM message:
5158

@@ -72,18 +79,18 @@ The function returns a `Weight` struct containing `refTime` and `proofSize` valu
7279

7380
### Execute a Message
7481

75-
The `execute` function runs an XCM message locally using the caller's origin. This is useful for executing XCM instructions that don't require cross-chain communication.
82+
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.
7683

77-
To execute a message:
84+
Follow these steps to execute a message:
7885

79-
1. Call `callWeighMessage` with your XCM message to get the required weight
86+
1. Call `callWeighMessage` with your XCM message to get the required weight.
8087
2. Use the returned weight values when calling `callXcmExecute`
8188
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:
8289

8390
- `message`: The encoded XCM message bytes.
8491
- `weight`: The `Weight` struct returned from `callWeighMessage`.
8592

86-
You can examine the complete extrinsic structure for this operation [here](https://dev.papi.how/extrinsics#networkId=localhost&endpoint=wss%3A%2F%2Ftestnet-passet-hub.polkadot.io&data=0x1f03050c000401000003008c86471301000003008c8647000d010101000000010100368e8759910dab756d344995f1d3c79374ca8f70066d3a709e48029f6bf0ee7e0750c61e2901daad0600){target=\_blank}.
93+
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.
8794

8895
5. Click on the **Transact** button to execute the xcm message:
8996

@@ -97,21 +104,21 @@ Additionally, you can verify that the execution of this specific message was suc
97104

98105
### Send a Message
99106

100-
The `send` function transmits an XCM message to a destination chain. This is the core functionality for cross-chain communication.
107+
The `send` function is responsible for transmitting an XCM message to a destination chain, enabling essential cross-chain communication.
101108

102109
To send a message:
103110

104-
1. Prepare your destination location encoded in XCM format
105-
2. Prepare your XCM message (similar to the execute example)
106-
3. Call `callXcmSend` with both parameters
111+
1. Prepare your destination location encoded in XCM format.
112+
2. Prepare your XCM message (similar to the execute example).
113+
3. Call `callXcmSend` with both parameters.
107114

108115
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.
109116

110-
Unlike `execute`, the `send` function doesn't require a weight parameter since the destination chain will handle execution costs according to its own fee structure.
117+
Unlike `execute`, the `send` function doesn't require a weight parameter since the destination chain will handle execution costs according to its fee structure.
111118

112119
## Cross Contract Calls
113120

114-
Beyond direct interaction and wrapper contracts, you can integrate XCM functionality directly into your existing smart contracts by inheriting from or importing the `IXcm` interface. This approach enables you to seamlessly embed cross-chain capabilities into your application logic.
121+
Beyond direct interaction and wrapper contracts, you can integrate XCM functionality directly into your existing smart contracts by inheriting from or importing the `IXcm` interface. This approach enables you to embed cross-chain capabilities into your application logic seamlessly.
115122

116123
Whether you're building DeFi protocols, governance systems, or any application requiring cross-chain coordination, you can incorporate XCM calls directly within your contract's functions.
117124

0 commit comments

Comments
 (0)