Remote Transact via XCM
This section contains contents for developers only.
XCM message format is generally used for low level instruction and information exchange between parachains and can cause loss of funds if used improperly.
Network users are advised to use dApps and tooling built around XCM instead.
Feature Overview
The XCM Transact
instruction allows the sender to execute arbitrary calls on the destination chain. This feature is extremely useful since it allows us to control accounts on a remote chain.
For example, a user can send a Transact
instruction from Astar to Polkadot that transfers DOT
from their derived account on Polkadot to an arbitrary receiver account on Polkadot. They don't need to interact directly with the Polkadot chain, but nevertheless are able to change its state. It's important to note that this is only one example - any call that can be interpreted by the remote (destination) chain is able to be sent and executed.
This is of particular use for smart contracts, since it allows them to integrate custom logic for cross-chain interoperability.
It's important to understand the difference between sending an XCM instruction sequence and receiving/interpreting it.
Sending an XCM transaction from Astar
or Shiden
to a remote chain may be successful on the sender side, but fail to execute on the destination, and the same is true for the opposite scenario. This can happen for multiple reasons - the XCM sequence might be incorrect, the remote chain doesn't know how to inrerpret the provided call
, or the remote chain doesn't allow remote execution, at all.
The developer or user must ensure that the destination chain supports the encoded call and remote transactions, in general, before they initiate the XCM transaction.
Remotely Transact on Astar/Shiden/Shibuya
XCM Sequence
At the moment, remote execution from origins other than parachain accounts are only allowed to be initiated by the Shibuya
runtime and Shiden
runtime.
A permissible sequence of instructions will therefore have to start like:
DescendOrigin
WithdrawAsset
BuyExecution
Transact
orSetAppendix
or whatever user wants
This XCM sequence, used as a prefix, may be followed by arbitrary instructions, for example: Transact
.
Although we cannot guarantee it, other chains will most likely adopt the same or a similar prefix for XCM instruction sequences.
DescendOrigin
The DescendOrigin parameter ensures that the origin isn't a parachain, but a more complex junction like { parachain: 2006, accountId: 0x123aff....ff }
. If this is omitted, all calls will be executed as if they were sent from the root-only parachain's sovereign account, which we do not allow.
WithdrawAsset
Withdraws assets on the destination chain from the derived sender account. The account must have the specified asset and the requested amount, otherwise the instruction will fail. These assets are used to pay for the XCM execution time.
BuyExecution
Buys XCM executuion time, using the withdrawn assets.