🍌
EVM-XCM Jungle Toolkit
  • πŸ“—Introduction
    • 🌴What is the EVM-XCM Jungle Toolkit?
    • 🧐Why use this toolkit?
    • πŸ‘ͺWho is this toolkit made for?
    • βš’οΈWhat tools are this toolkit made of?
  • ↔️Build an EVM+Substrate wallet compatible architecture in your dApp
    • ⁉️Two different standards
      • ℹ️Addresses Format
      • 🎭Public Key vs Hash-based
      • πŸ“©Multichain compatibility
      • ⚑Account Types
    • β˜‘οΈRecommended wallets
      • 🦊MetaMask
      • ☸️SubWallet
      • 🀚Talisman
    • 🟒The EVM address standard
      • πŸ”Get an address for a Signer
        • πŸ‘οΈCheck the validity of the address
      • πŸ’°Get the native balance of a Signer
        • Get an ERC20 token's balance
      • πŸŽ‡Get the chain information for a Signer
    • πŸ”΅The Substrate address standard
      • πŸ”Get an address for a Signer
        • πŸ‘οΈCheck the validity of the address
      • πŸ’°Get the native balance of a Signer
      • πŸŽ‡Get the chain information for a Signer
    • πŸ“§Mapping of addresses
    • 🀝Implement multiple wallet support on your dApp front-end
      • πŸ’šUnderstanding the EVM provider/signer concepts
      • ❀️Understanding the Keyring concept
      • πŸ”‘Sign and send EVM transactions
      • πŸ—οΈSign and send Substrate extrinsics
    • πŸ“šRessources
  • ➑️Build a cross-chain transaction from any EVM-chain to a Substrate-based chain using IBC and XCM
    • ⁉️Understanding the flow
    • πŸ¦‘Transfer tokens to Moonbeam Parachain using Squid SDK from any EVM chain
    • πŸͺCreate & execute a transaction on the source chain before bridging tokens (pre-hook)
    • πŸͺCreate & execute a transaction on Moonbeam after bridging tokens (post-hook)
    • ✨Create & execute a swap using Stellaswap pools to obtain xcTokens
    • πŸ™ŒWrap-up
    • πŸ“šRessources
  • ⬅️Build a cross-chain transaction from a Substrate-based chain to Moonbeam chain
    • ⁉️Understanding the flow
    • πŸ’‘Using LightSpell API to generate valid XCM calls
    • πŸŒ‰Transfer tokens between parachains (or relay chain) using XCM and ParaSpell SDK
    • πŸ™ŒWrap up
    • πŸ“šRessources
  • ⏩Build batches on source and destination chains using Squid and batch precompile
    • ⁉️Understanding the flow
    • πŸ‘ŒUnderstanding the batch precompile
    • βœ…Create a batch transaction compatible with Squid router
    • πŸͺIntegrate a batch into a Hook using Squid
    • πŸ™ŒWrap up
    • πŸ“šRessources
  • πŸ”Build a gas-less transaction from/to an EVM/Substrate chain using callPermit
    • ⁉️Understanding the flow
    • πŸ”‹Generating the data to sign
    • ✍️Collecting the signature
    • 🌐Relaying the signature
    • ⚑Executing the transaction
    • πŸ™ŒWrap up
    • πŸ“šRessources
  • πŸ”€Build a custodial solution to make your dApp wallet-less & gas-less using EIP-712
    • ⁉️Understanding the flow
    • ⛓️Smart contract
    • βš™οΈBack end
  • πŸ”½Examples of working cross-chain dApps made using the Jungle Toolkit
    • 🌴Case Study: The Great Escape
      • The Player Structure
      • The xDeposit Function
      • The xRegister Function
Powered by GitBook
On this page
  • Obtain an integrator-id to build with Squid
  • Get a route using the Squid SDK
  • Initiate the SDK
  • Forge the route request parameters
  • Get a route using the Squid API
  • Initiate the API
  • Forge the route request
  • Example Route Request parameters (from 1 MATIC to GLMR)
  • Currently available tokens on Moonbeam as destination chain
  1. Build a cross-chain transaction from any EVM-chain to a Substrate-based chain using IBC and XCM

Transfer tokens to Moonbeam Parachain using Squid SDK from any EVM chain

How to leverage Squid router to teleport easily tokens to Moonbeam parachain, the EVM gateway of the Polkadot's ecosystem

Last updated 1 year ago

As explained in the previous sections, the flow will start on the source chain. For instance, let's say we'll do a cross-chain transaction from MATIC to Moonbeam. The flow will be handled by Squid router, using their SDK v2 leveraging IBC across chains.

A signer, aka the user, will start the process by signing a transaction, in our example he'll call the CALL_BRIDGE_CALL function of the Squid router adress on the Source chain.

The router can change its address so it's important to check the Squid documentation to get the latest address available.

As of December 23, you'll find these smart contracts at the following addresses:

  • Mainnet

    • SquidRouter

    • SquidMulticall

  • Testnet

    • SquidRouter

      • 0xC3468a191Fe51815b26535ED1F82C1f79e6Ec37D

    • SquidMulticall

      • 0x7a4F2BCdDf68C98202cbad13c4f3a04FF2405681

In order to execute the cross-chain transaction, Axelar General Message Passing protocol need a call properly forged containing all the required data. This is what we call a route in Squid API/SDK. To get a route that suits us, in our example a MATIC to GLMR swap, we can leverage both the Squid API and SDK. Let's see how both solutions are working.

Obtain an integrator-id to build with Squid

Get a route using the Squid SDK

Initiate the SDK

import { Squid } from "@0xsquid/sdk";

(async () => {
  // instantiate the SDK with config
   const squid = new Squid({
    baseUrl: "https://v2.api.squidrouter.com",
    integratorId: "your-integrator-id"
  });

  // init the SDK
  await squid.init();
  console.log("Squid inited");
})();

Forge the route request parameters

// Set up parameters for swapping tokens and depositing into Radiant lending pool
const params = {
  fromAddress: signerAddress,
  fromChain: polygonId,
  fromToken: nativeToken,
  fromAmount: amount,
  toChain: moonbeamId,
  toToken: nativeToken,
  toAddress: signerAddress,
  slippage: 1,
  slippageConfig: {
    autoMode: 1,
  },
  quoteOnly: false,
};

// Get the swap route using Squid SDK
const { route, requestId } = await squid!.getRoute(params);

fromAddress should be equal to msg.sender later in the transaction

fromChain and toChain should be chain IDs a String

fromAmount and toAmount should be formatted numbers with the appropriate decimals as String

Get a route using the Squid API

Initiate the API

const baseUrl = "https://v2.api.squidrouter.com/v2"

// get an integrator-id https://form.typeform.com/to/cqFtqSvX
const integratorId = "<you-integrator-id>"

// Set up JSON RPC provider and signer
const provider = new ethers.providers.JsonRpcProvider(<source-chain-rpc-endpoint>);
const signer = new ethers.Wallet(<privateKey>, provider);

Forge the route request

const getRoute = async (params: any) => {
  try {
    const result = await axios.post(
      "https://v2.api.squidrouter.com/v2/route",
      params,
      {
        headers: {
          "x-integrator-id": integratorId,
          "Content-Type": "application/json",
        },
      }
    );
    const requestId = result.headers["x-request-id"];
    return { data: result.data, requestId: requestId };
  } catch (error) {
    // Log the error response if it's available.
    if (error.response) {
      console.error("API error:", error.response.data);
    }
    console.error("Error with parameters:", params);
    throw error;
  }
};

// Get the swap route using Squid API
const routeResult = await getRoute(params);
const route = routeResult.data.route;
const requestId = routeResult.requestId;
console.log("Calculated route:", route);
console.log("requestId:", requestId);

Example Route Request parameters (from 1 MATIC to GLMR)

{
    "fromChain": "137",
    "fromAmount": "1000000000000000000",
    "fromToken": "0xEEeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
    "toChain": "1284",
    "toToken": "0xEEeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
    "fromAddress": signerAddress,
    "toAddress": signerAddress,
    "slippageConfig": {
        "autoMode": 1
    }
}

Note: 0xEEeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee is used for native tokens

Currently available tokens on Moonbeam as destination chain

  • GLMR

  • xcDOT

  • Wormhole assets

    • USDC

    • BTC

    • ETH

To get an integrator-id, you'll need to fill a quick form about yourself and your project. It literally takes 5mn and it's mandatory to make the calls work, so everything starts with

➑️
πŸ¦‘
0xce16F69375520ab01377ce7B88f5BA8C48F8D666
0x4fd39C9E151e50580779bd04B1f7eCc310079fd3
this link.