2

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?

2 Answers 2

2

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.

1
  • This is awesome. Thanks!
    – Bruno
    Commented Oct 10 at 13:35
1

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.

3
  • Are you sure that bagpipes can be helpful for figuring out these kinds of XCM interactions? I have never been able to use it successfully for these kinds of things... Also, I'm very surprise to read this, since AFAIK neither POP network nor the Paseo relay chain are available options in their list of available chains ¯_(ツ)_/¯
    – Josep
    Commented Oct 9 at 22:37
  • Great question. Pop Testnet (Pop Network on Paseo) is already supported if you run Bagpipes locally, github.com/xcmsend/app, will link the public instance soon
    – Bruno
    Commented Oct 10 at 13:34
  • Does the local version use a more modern version of XCM? Because the live one still uses V2...
    – Josep
    Commented Oct 10 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.