I have read the XCM documentation:
And I would like to construct a simple XCM on PolkadotJs Apps from AssetHub to Pop Network.
How do I do this?
I have read the XCM documentation:
And I would like to construct a simple XCM on PolkadotJs Apps from AssetHub to Pop Network.
How do I do this?
An example on how to do this with PAPI. Please notice that all the fields are strongly typed, and that the names of the types are indicating how to properly construct the variants.
TL;DR:
And copy & paste this encoded call data as an example:
0x1f0803000100853e0300010100d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d030400000000419c0000000000
Below is an example of doing a limited reserve transfer asset XCM. The same methodology can be applied to other XCM's.
We need to use the XCM pallet on AssetHub. In PolkadotJs Apps it is named: PolkadotXcm.
Using that pallet, we construct our XCM.
First, we specify the destination location in the form of a MultiLocation
:
From the Relay chain, it is one junction down (X1) and it is a parachain with paraId 4001.
Next, we need to define who will be the beneficiary, also in the form of a MultiLocation
:
Note that the address has to be in hex format.
Finally, we define the asset (fungible, nonfungible, amount, etc), in the form of a MultiAsset
:
You could also construct the above programmatically using the PolkadotJs API. e.g.
const getReserveTransferParams = (to, amount) => {
const parachainId = 4001;
const dest = {
V3: {
parents: '0',
interior: {
X1: {Parachain: parachainId},
},
},
};
const beneficiary = {
V3: {
parents: '0',
interior: {
X1: {
AccountId32: {
network: null,
id: to,
},
},
},
},
};
const assets = {
V3: [
{
id: {
Concrete: {
parents: 0,
interior: {
Here: '',
},
},
},
fun: {
Fungible: amount,
},
},
],
};
const fee_asset_item = '0';
const weight_limit = 'Unlimited';
return [dest, beneficiary, assets, fee_asset_item, weight_limit]
}
Bonus points if you use the new Polkadot API (PAPI)
Example using Polkadot API (PAPI) to do an XCM teleport:
Here is another XCM:
And the actual extrinsic payload for the above call:
One handy tip (or hack) for constructing XCM's is to structure the call in contracts.onpop.io, then in Talisman (don't submit the tx), copy the encoded call data for the contract call. This is just for the contract call though :)
https://bagpipes.io can also be helpful for figuring out XCM interactions.