How to do a Balance Transfer via XCM?

How to do a Balance Transfer via XCM?

A step-by-step guide to do a Balance Transfer via XCM between Moonbeam and Manta Network.

Intro

In this guide, we will be demonstrating how to do a balance transfer using XCM. This will involve transferring funds from an account on Moonbase Alpha to a destination account on Calamari or the Manta deployment on Moonbase testnet. This is part of our event series Privacy on Moonbeam. You can find a complete workshop on how to build a private dApp with Moonbeam here. 

Before we begin, there are a few things that we will need to have to complete this process:

  1. An account on Moonbase Alpha that is funded with our token DEV
  2. A MultiLocation derivative account. This can be easily calculated using the script provided here.
  3. Calamari testnet tokens, which can be used to fund the MultiLocation derivative account. You can request the testnet tokens over the Manta Network Discord on the #mantapay-v3-faucet channel. 
  4. The ability to build an encoded call or bytes that Calamari can understand.
  5. The ability to build an XCM message on Moonbeam.

Other important links can be found here: 

  1. Polkadot.js Moonbase Alpha
  2. Docs on Remote XCM Calls 
  3. Docs on Remote EVM Calls 
  4. XCM-tools Github Repo

We encourage you to use the guide for written support. You have the full demo in the video below. 

Step 1: Calculate MultiLocation Derivative Account

Use the script provided in the URL to calculate the MultiLocation derivative account. Once calculated, fund it with the Calamari testnet tokens.

Step 2: Build Encoded Call on Kalamari

Head to Calamari on Moonbase and build the transaction. You can cheat and build it in the interface, but then you will need to copy it down. The encoded call data, or bytes, represent a balance transfer to a specific account and value.


Step 3: Build XCM Message on Moonbeam

Head to Moonbeam Alpha and build the XCM message using the remote transactor pallet, a module that will help you build an XCM message without having to build it piece by piece. Use the transact through sign method and provide the necessary information.


Step 4: Set Dispatcher Account on Moonbase Alpha

Our dispatcher account on Moonbase Alpha needs to have tokens to pay for the execution. In this case, we are telling Manta or Calamari which tokens to take out of the MultiLocation derivative account to pay for this execution. In Moonbase terms, this means the Calamari token on KMA.


Step 5: Set the Token as a Multi-Location

There is a mapping between the two, and we can specify the token as a MultiLocation. The easiest way to do this is as a currency ID, which is the asset ID. In this case, it’s not the reserve token of Moonbase, but a foreign reserve. The asset ID can be found in the Network Assets section, it is 213357169630950964874127107356898319277.

Step 6: Set the Weight

The weight is related to the time of execution that this will take. In this case, we are giving 2 billion weight units to be executed. One weight unit is equal to one picosecond.

Additionally, the overall XCM message also needs to have weight units provided for the execution of all the instructions mentioned before. This number has to be larger than the number provided for the action, because it includes the XCM message plus the weight for the transact.

Step 7: Buy Execution

You will need to buy some execution, which will be 3 billion weight units or the amount that you are withdrawing. The lease execution will be the one that limits you out.


Step 8: Transact Instruction

When you transact instruction which will execute the bytes and use the specified weight. Keep in mind that this XCM message was crafted on the moving side and the palette does this for you in a more secure way, so you don’t have to worry about all the little details.

receive the quarterly state of zk report

New publication: Read our State of ZK Report for Q3
This is default text for notification bar