Best Resources to Learn XCM (Tech & High Level)

Let’s use this thread to collect some of the best resources available in the community to get up to speed on XCM, both from a technical / development perspective, and from a non-technical / high level perspective.

Discussion welcome, especially if there are suggestions for new material and resources which does not yet exist.

Technical Resources

Non-Technical Resources

My list is a little biased, based on the resources we have created at Parity, but looking forward to see your contributions too.

14 Likes

On a tech level, the audit report by Quarkslab is a very good and detailed reference for XCM v2:

2 Likes

This is super good :100:

Another good one for XCM assets.
Keith Yeung, How can I transfer assets using XCM? - Substrate StackExchange

4 Likes

This is useful:

Adding one more here, XCM demo session by @stiiifff and @hectorb from the last Sub0 - Parity Technologies: Trappist: Thinking cross chain applications with XCM | Sub0 2022 - YouTube

Pretty cool from a application builders’ perspective.

1 Like

The 3-part series of blog posts by Gav in '21 are also a good place to start:

  1. XCM: The Cross-Consensus Message Format
  2. XCM Part II: Versioning and Compatibility
  3. XCM Part III: Execution and Error Management

For those that want to get even deeper into the code and try things out regarding the latest in XCM, looking at the XCM simulator is probably the best way to get your hands dirty.

[polkadot/lib.rs at d528437edd3f966571748a7a0c8f47f9954d1ec4 · paritytech/polkadot · GitHub]

You can check out the tests and raw XCM instructions there, and play with things yourself! For example:

	/// Scenario:
	/// The relay-chain teleports an NFT to a parachain.
	///
	/// Asserts that the parachain accounts are updated as expected.
	#[test]
	fn teleport_nft() {
		MockNet::reset();

		Relay::execute_with(|| {
			// Mint the NFT (1, 69) and give it to our "parachain#1 alias".
			assert_ok!(relay_chain::Uniques::mint(
				relay_chain::RuntimeOrigin::signed(ALICE),
				1,
				69,
				child_account_account_id(1, ALICE),
			));
			// The parachain#1 alias of Alice is what must hold it on the Relay-chain for it to be
			// withdrawable by Alice on the parachain.
			assert_eq!(
				relay_chain::Uniques::owner(1, 69),
				Some(child_account_account_id(1, ALICE))
			);
		});
		ParaA::execute_with(|| {
			assert_ok!(parachain::ForeignUniques::force_create(
				parachain::RuntimeOrigin::root(),
				(Parent, GeneralIndex(1)).into(),
				ALICE,
				false,
			));
			assert_eq!(
				parachain::ForeignUniques::owner((Parent, GeneralIndex(1)).into(), 69u32.into()),
				None,
			);
			assert_eq!(parachain::Balances::reserved_balance(&ALICE), 0);

			// IRL Alice would probably just execute this locally on the Relay-chain, but we can't
			// easily do that here since we only send between chains.
			let message = Xcm(vec![
				WithdrawAsset((GeneralIndex(1), 69u32).into()),
				InitiateTeleport {
					assets: AllCounted(1).into(),
					dest: Parachain(1).into(),
					xcm: Xcm(vec![DepositAsset {
						assets: AllCounted(1).into(),
						beneficiary: (AccountId32 { id: ALICE.into(), network: None },).into(),
					}]),
				},
			]);
			// Send teleport
			let alice = AccountId32 { id: ALICE.into(), network: None };
			assert_ok!(ParachainPalletXcm::send_xcm(alice, Parent, message));
		});
		ParaA::execute_with(|| {
			assert_eq!(
				parachain::ForeignUniques::owner((Parent, GeneralIndex(1)).into(), 69u32.into()),
				Some(ALICE),
			);
			assert_eq!(parachain::Balances::reserved_balance(&ALICE), 1000);
		});
		Relay::execute_with(|| {
			assert_eq!(relay_chain::Uniques::owner(1, 69), None);
		});
	}

You can execute it by cloning Polkadot and running:

cargo test -p xcm-simulator-example
1 Like

A really nice resource on the finer details of XCM and how it’s configured, along with a deep dive on the pallet - super useful on getting a more hands-on look at how XCM is implemented (kudos @bernardoaraujor):

3 Likes

Great resources guys! Thank you, it will help to better understanding and easier to onboard people! Can’t wait to spread our xcBAI to the Polkadot world through the XCM! :white_check_mark:

An initial deepdive on XCM v3 - really good stuff, considering how there isn’t too much in-depth info on v3 yet!

3 Likes

Little late to the party, but we work on a tool that unifies cross-chain experience for dApp developers by wrapping the XCM pallet of each compatible parachain. It is very easy to implement also! Might be helpful to someone :). We are open to any implementation and are going to work on any issues raised asap.

Docs: What is ParaSpell✨ | ParaSpell
Organization: ParaSpell · GitHub

1 Like

I want to add here more practical resources:

The last 2 deep dives, both about XCM.

And the repository with examples from the XCM Docs: https://github.com/paritytech/xcm-docs/tree/main/examples.
Very recommended to clone this repository and play with these examples.

4 Likes