Skip to main content

XTokens

Constructing an XCM message for asset transfers between parachains can be challenging. However, to simplify this process, developers can make use of wrapper functions and pallets that enable the use of XCM features on peaq/krest.

One such wrapper is the XTokens Pallet, which offers various methods for transferring fungible assets via XCM.

Functions

  1. transfer(currencyId, amount, dest, destWeightLimit) — Transfer a currency, defined as either the native token (self-reserved) or with the asset ID.

  2. transferMultiasset(asset, dest, destWeightLimit) — Transfer a fungible asset, defined by its multilocation.

  3. transferMultiassetWithFee(asset, fee, dest, destWeightLimit) — Transfer a fungible asset, allowing the sender to pay the fee with a different asset. Both are defined by their multilocation.

  4. transferMultiassets(assets, feeItem, dest, destWeightLimit) — Transfer several fungible assets, specifying which one is used as the fee. Each asset is defined by its multilocation.

  5. transferMulticurrencies(currencies, feeItem, dest, destWeightLimit) — Transfer different currencies, specifying which one is used as the fee. Each currency is defined as either the native token (self-reserved) or the asset ID.

  6. transferWithFee(currencyId, amount, fee, dest, destWeightLimit) — Transfer a currency, allowing the sender to pay the fee with a different asset. Both are defined by their multilocation.

The required inputs can be specified as follows:

  • currencyId/currencies: The identifier or identifiers of the currency or currencies being sent through XCM. Various runtimes may have distinct methods for defining these IDs.

  • amount: The quantity of tokens intended for transmission through XCM.

  • dest: Multilocation is utilized to designate the target address for tokens being transmitted via XCM. It accommodates various address formats, including 20 or 32-byte addresses (Ethereum or Substrate).

  • destWeightLimit: Enum that determines the maximum execution time allocated in the destination chain for executing the transmitted XCM message. This enum offers the subsequent choices:

      Unlimited: Permits the full gas amount to be employed for weight payment.
    Limited: Constrains the gas amount for weight payment to a specified value.

Note If not enough weight is provided, the execution of the XCM will fail, and funds might get locked in either the Sovereign account or a special pallet. It is important to correctly set the destination weight to avoid failed XCM executions.

  • asset/assets: Multilocation used to specify the asset/assets intended for transmission through XCM. Different parachains adopt varying methods to reference assets. For instance, peaq/krest networks utilize the Balances Pallet index to reference their native tokens.

  • fee: Token for covering the XCM execution costs on the target chain.

  • feeItem: Index utilized to specify the asset position within an array of assets being sent. This position is used to cover the XCM execution expenses on the target chain. For instance, when sending a single asset, the feeItem would be 0.

Constants

  • baseXcmWeight() - provides the XCM weight necessary for execution.
  • selfLocation() - provides the multilocation of the chain.