7

I transferred some KSM from the Kusama relay chain to the Karura parachain, and now I want to withdraw the tokens back to the relay chain.

That said, it seems that currently the Karura graphical interface is not working (down for meintenance) so I can't use the standard way of bridging the assets out of Karura back to Kusama.

How can I go about withdrawing the KSM tokens directly without having to use the Karura graphical interface?

Karura Bridge UI

1 Answer 1

8

You can withdraw the assets by submitting an XCM extrinsic directly to the Karura parachain (this applies to any parachain that uses the xtokens pallet: xtokens).

This can be done from the command line, but the easier way is to use the Polkadot.js interface for the relevant parachain, the Karura interface can be found here: Karura - Extrinsics.

An example of an xToken transfer in a JSON format looks like this:

[
  {
    name: "currency_id",
    type: "acala_primitives:currency:CurrencyId",
    type_name: "CurrencyId",
    value: {
      Token: "KSM"
    }
  },
  {
    name: "amount",
    type: "U128",
    type_name: "Balance",
    value: "123400000000"
  },
  {
    name: "dest",
    type: "xcm:VersionedMultiLocation",
    type_name: "Box<VersionedMultiLocation>",
    value: {
      V1: {
        interior: {
          X1: {
            AccountId32: {
              id: "0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a",
              network: {
                Any: null
              }
            }
          }
        },
        parents: 1
      }
    }
  },
  {
    name: "dest_weight",
    type: "U64",
    type_name: "Weight",
    value: 5000000000
  }
]

Arg 1: currency_id defines the token you want to transfer - in our case it's KSM.

Arg 2: amount defines the amount of tokens you want to transfer - this value uses base units so 1 KSM is 1000000000000 in base units - in our case 123400000000 is equal to 0.1234 KSM

Arg 3: dest defines the destination address to which we want to send the tokens - note that this is the 32 byte account ID and not the SS58 address format (you can get the account ID from an address using the subkey inspect <SS58> command in the terminal).

Note: The parent junctions parameter parents should be set to 1 as we are sending the funds to an external address on the relay chain (i.e. 1 level up in the consensus hierarchy).

Arg 4: dest_weight defines the weight for XCM execution on the destination chain - here we set a constant of 5000000000.

Using the Polkadot.js interface we can fill out the xTokens.transfer() extrinsic information like so:

Extrinsics interface

We can then submit the transaction and the KSM tokens should be transferred from Karura to Kusama when the transaction is included in the chain.

8
  • 1
    I think you should mention that the parents field of the destination MUST be 1, otherwise it stays at 0 and it gets sent back to your own account. Mar 18, 2022 at 6:55
  • @KeithYeung Thanks, I updated the answer.
    – Dcompoze
    Mar 18, 2022 at 7:07
  • Your note is still a bit inaccurate -- the reason why you must set the parents parameter to 1 is because you are specifically sending funds to an account on the relay chain, and parents: 1 signifies the location that's "one level up" from the Karura parachain, i.e. the Kusama relay chain. Mar 18, 2022 at 15:43
  • orml-xtokens is some high level xcm wrapper, maybe better to use some low level InitRerserveWithDraw primitives to demonstrate and parents: 1 is just the destination from the view of parachain but not the canonical repensentation for KSM in relaychain which should be parents:0,Here instead
    – Ron
    Mar 19, 2022 at 15:33
  • If you have an example with lower-level XCM primitives it would be interesting to see - feel free to create another answer.
    – Dcompoze
    Mar 20, 2022 at 0:35

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.