# Frustration with XCM in JavaScript

**URL:** <https://forum.polkadot.network/t/frustration-with-xcm-in-javascript/474>\
**Category:** Tech Talk\
**Created:** [September 22, 2022, 12:44pm UTC](https://forum.polkadot.network/t/frustration-with-xcm-in-javascript/474 "2022-09-22T12:44:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bitcoinwarrior](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.polkadot.network/bitcoinwarrior/32/282_2.png) [@bitcoinwarrior](https://forum.polkadot.network/u/bitcoinwarrior)\
**Post date:** [September 22, 2022, 12:44pm UTC](https://forum.polkadot.network/t/frustration-with-xcm-in-javascript/474/1 "2022-09-22T12:44:33Z")

</div>

Originally posted on reddit: [https://www.reddit.com/r/dot/comments/xkp4g1/frustration\_with\_xcm\_in\_javascript/](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](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fbasilisk-rpc.dwellir.com#/extrinsics/decode/0x34030208000400010200e12e0500000b00e057eb481b0e010004010100411f081300010200e12e050000070010a5d4e80107001c040a5d0d010004000101008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48001c040a5d000000)

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.

---

<div class="post-metadata">

**Author:** ![rphmeier](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.polkadot.network/rphmeier/32/126_2.png) [@rphmeier](https://forum.polkadot.network/u/rphmeier)\
**Post date:** [September 23, 2022, 3:35am UTC](https://forum.polkadot.network/t/frustration-with-xcm-in-javascript/474/2 "2022-09-23T03:35:28Z")

</div>

To actually answer you, yes, XCM (and everything else binary to do with the blockchain) is encoded with SCALE. There are libraries, e.g. those under the polkadot-js umbrella or [the scale library](https://github.com/paritytech/parity-scale-codec-ts) by ParityTech.

This type of content is better for the StackExchange, not for the ‘Tech Talk’ forum which is meant for high-signal low-noise deep technical discussion.

---

<div class="post-metadata">

**Author:** ![super.admin](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@super.admin](https://forum.polkadot.network/u/super.admin)\
**Post date:** [September 23, 2022, 11:14am UTC](https://forum.polkadot.network/t/frustration-with-xcm-in-javascript/474/4 "2022-09-23T11:14:50Z")

</div>


