Originally posted on reddit: https://www.reddit.com/r/dot/comments/xkp4g1/frustration_with_xcm_in_javascript/?
Talisman and I are looking into building a simple JS module that helps developers build XCM for transactions and abstract common patterns like cross chain transfers into a simple JS function taking inputs like: fromParachain, toParachain, assetId, recipient etc.
These functions would then return the XCM object and allow the developer to encode it into hex so that it can be submitted to the network via the submitExtrinsic
call.
I am currently working on an example transfer which would allow a user to transfer an asset from one parachain to another. You can see it here: Polkadot/Substrate Portal
However, I am running into the following difficulties:
- How does one encode the XCM into hex? I know that this is possible as it is done on the web interface but there is very little insight into how this is actually done in practice. I have tried looking through the web portal’s code but it is so abstract. I want to be able to build and encode the XCM I have in the above link.
- XCM itself is not parsable in JavaScript, it looks like JSON but it isn’t. I am struggling to understand how we can formulate such a simple XCM message in JavaScript and then encode it into hex so it can be submitted as a transaction. I know that it is using something called SCALE but I am at a loss as to how to use it and import the types available in XCM v2.
I am also curious to hear from developers as to whether they believe such a module would be useful for them. I know that it is currently very difficult to make an XCM transaction in polkadot.js so I imagine this would be a very important piece of infrastructure.
Please help.