πŸ’‘Using LightSpell API to generate valid XCM calls

To move assets between a parachain to another parachain or directly to the relay chain, we need to sign an extrinsic to create a proper XCM message

"XCM is too complicated"

When it comes to XCM, it appears that it's often seen as a complicated tech, even sometimes obscure. The fact is, it is not and by using the proper tools, you can teleport tokens very easily in several directions, in a trusless and interoperable way. Better than easy, these operations between chains are very fast (about a minute) and not too costy regarding gas.

LightSpell and ParaSpell: the secret ingredients

To teleport our assets, we'll use LightSpell XCM API and Paraspell XCM SDK which are two very handy tools facilitating the task. Basically, these tools are doing the computation allowing us to focus on what we really want to achieve. A bit like Squid before, we just have to forge a proper route request to obtain a valid XCM call, easily executable later on.

Asking for a XCM route using ParaSpell API

const xcmApiUrl = "https://api.lightspell.xyz/";

// Construct XCM call from Relay chain to Parachain (DMP)
const dmpResponse = await fetch(
    `${xcmApiUrl}/x-transfer?` +
    new URLSearchParams({
        to: "Moonbeam",   // Replace "Moonbeam" with the destination Parachain
        amount: 100,      // Replace 100 with the amount you wish to transfer (Numeric value)
        address: "0x1234" // Replace "0x1234" with the destination wallet address (In AccountID32 or AccountKey20 Format)
    })
);

// Construct XCM call from Parachain chain to Relay chain (UMP)
const umpResponse = await fetch(
    `${xcmApiUrl}/x-transfer?` +
    new URLSearchParams({
        from: "Acala",    // Replace "Acala" with the sender Parachain
        amount: 200,      // Replace 200 with the amount you wish to transfer (Numeric value)
        address: "0x5678" // Replace "0x5678" with the destination wallet address (In AccountID32 or AccountKey20 Format)
    })
);

// Construct XCM call from Parachain to Parachain (HRMP)
const hrmpResponse = await fetch(
    `${xcmApiUrl}/x-transfer?` +
    new URLSearchParams({
        from: "Acala",      // Replace "Acala" with the sender Parachain
        to: "Moonbeam",     // Replace "Moonbeam" with the destination Parachain
        currency: "DOT",    // Replace "DOT" with asset id or symbol
        amount: 300,        // Replace 300 with the amount you wish to transfer (Numeric value)
        address: "0xABCD"   // Replace "0xABCD" with the destination wallet address (In AccountID32 or AccountKey20 Format)
    })
);

Last updated