Native Interoperability on Moonbeam Through XCM
ETHCC 5 · July 2022 · 53:14
Alberto Viera introduces XCM interoperability for Moonbeam and the Polkadot/Kusama ecosystem. The workshop examines messaging between parachains and how to construct a token-transfer message.
Speakers
Topics
From ETHCC 5, hosted by Ethereum France.
Transcript
oh sorry all right uh yeah so yeah my name is alberto and today i'll be talking about moonbeam and more specifically nature for interoperability on moving through xcm so if you don't know xcm is this like technology that allows different blockchains in the polkadot ecosystem to talk with each other right so that's that's the fairly cool part about pokedot like i said before i'm alberto and i work at developer relations if you have any questions at any point let me know so yeah raise your hand and i'm happy to answer any questions so um today we're going to do a sort of like a little bit of a presentation about the project and then you know do the demo itself it's going to be like half and half but the idea is to give
you sort of an overview of of polka dot moonbeam and then interoperability and so we're going to do a little introduction about polka dot what it is because a lot of people still don't know what pokedot is then we're going to talk about moonbeam what is it specifically and why is it special and last but not least we're going to talk about interoperability what boom offers and a little workshop to show you guys what are we working on i do really like this this uh dosh meme because you know it's like you know delicious everyone loves the dosh and just basically you know shows you what moomim is all about right it's about bringing ethereum developers closer to the polka dot ecosystem basically so um polkadot in one minute um you're not going to be an expert about polka
dot after this one minute slide but the idea is to give a little bit of context on what poke that is and what the promise of polka dot is basically so the main idea about polka dot is a specialization right is that there's no one blockchain to rule them all there are many best blockchains in the space and polkadot will connect these blockchains and we'll secure them all right so polkadot provides finality to the blocks which is really important and make sure that all the all the blockchains that are connected to this sort of hub or like you know this sort of mothership um are secured and interconnected that's that's the main idea and so uh usually people in the space refer to polka dot as a relay chain or some other people layer zero so you know layer one you know layer two
then you have layer zero which is up above layer ones and so um the pair of chains are these blockchains that connect to polka dot right and they provide specific functionalities to the ecosystem so instead of you having sort of like a chain that it tries to be good at everything you have specific chains for for example privacy specific chains that are all like tuned in for storage you have identity oracle bridges d5 so you have all the participants that together bring sort of like a broader ecosystem that provides functionalities to everyone and then one of these pair chains is moonbeam and i'll explain it in the next slide so the important thing once again is that you cannot really build stuff on polka dot you know if
you've ever used polka dot you cannot really build on top of it you can just take and do governance right so the idea is that polka dot it's a specialized chain to connect and secure these other specialized blockchains but the application layers will live actually in the spare chains and that's one of the biggest difference compared to other blockchains and the third thing that is really important is that um polkadot allows these participants to communicate with each other in a native way which is very different that what bridges allows you to do right now right when you communicate through bridges you have this middleman this like entity group of people relayers or whatever you want to call them that you actually rely on them and to communicate
with other blockchains right and you know we've all seen what happened with bridges we have the wormhole hack we have the ronin hack and so you have this trusted entity in the middle that sort of you're trusting it with xcm the difference here is that you already trust the polkadot security model because polkadot's finalizing your blocks has a sort of like a economic model to slash validators and everything so you can trust that at least the messages that you're passing are going to be relayed correctly there's not you know there's not going to be any middlemen that you need to rely on and so one really important thing to understand about polka dot is that polka dot is nothing without the pair of jeans but the parrot chains are nothing without polka dot it's a two-way relationship polkadot is not the almighty god you need parochians to
provide sort of like a fruitful echoes to have a fruitful ecosystem and the other thing is that polkadot it's all about interoperability if we don't have xcm there's nothing really special about polka dot it's just another blockchain blah blah blah nothing great with xcm is similar to cosmos right but there's some differences there with xcm you have all these participants natively and in the centralized trustless way that they're probably three favorite words about everyone in blockchain um communicate with each other right that's it that's all i have to say about polkadot so what it's move mean right if you've never heard about moonbeam uh mummy meets one of these para chains so one of these blockchains in the ecosystem and we we are specialized into
providing a full ethereum compatible environment on polka dot so if you have ever developed on ethereum you have used hard hat truffle ethers web3 javascript you can use all these tools on moonbeam from day one all right and so you know the core layer of any ethereum compatible chain is sort of the evm right so you have the evm avm everyone knows the evm but then we also have sort of added layers or features on top of dvm to provide extra functionalities the first one is that we're built with substrate if you don't know what substrate is it's sort of an sdk to build blockchains and the cool thing about substrate is that it allows you to really easily connect to pokedot for native interoperability right that's
that's one of the things that we want next we have the web3 rpc support and if you're a developer and you're familiar about what this means it allows you to have all the ethereum tools natively natively work on moonbeam right so basically any tool like metamask etheris hard hat they all use the east json rpc to communicate with an ethereum node and so we understand that language and that's why all these tools work natively with moonbeam we also have unified accounts if you're familiar with polkadot you know that you have the poke.js extension that has a different account system we forget about all that and we use the ethereum account system right so on moonbeam you will be doing staking you'll be doing governance you'll be doing ethereum smart contracts
interactions all with your ethereum accounts from ledger from metamask from math wallet whatever wallet that you use on ethereum it should work on moombi and last but not least we've really worked really really hard into making sure that moomin provides an ethereum development-like experience with expanded functionalities and i'll touch about the expanded functionalities in a bit but we also want to be an interoperability hub right so like i said before the idea of this image on the right is to show that we are more than just an evm implementation we have sort of these features that can differentiate moonbeam inside the polka dot ecosystem and hopefully outside of the pokedex system as well yep i think there's a mic because of this
live stream so yeah sorry can you just expand it just one sentence on the unified account so is this polka dot accounts and ethereum accounts unified or how what's unique yeah so that's a good question because if you are familiar with pokedot polkadot uses an account system that it's based on sr25519 cryptography right so it's sort of like deriving from the mnemonic seat deriving accounts in a different way than ethereum right so you can still have the same mnemonic seat but then you have bitcoin accounts ethereum accounts you'll have like sort of sort of like polka dot accounts the problem is that if you want to have a full evm compatibility you have an issue right
because to interact with the evm the evm is using ethereum style accounts which use ecdsa so elliptical curve blah blah blah and so the problem is that other other periching projects that have evm they sort of have to have ethereum accounts and polka dot accounts right and then if you want to do for example governance because that is like a substrate feature that is like a polka dot native feature bought on on this pair of chain you have to have this like substrate account so you have to use pocket.js extension sign the governance transaction and then all good but if you want to interact with evm you have to like send tokens from this account to the other account to be able to interact with the uvm and for us since we started moomin was like this doesn't make a lot
of sense because like we if you want to provide sort of like a frictionless ethereum environment the first thing that you go when you go into this project is like dude how do i interact with the evm right and so we basically modified the underlying code so that the when you check with who the signer is you're using edc ecdsa cryptography right so in in the world of moonbeam uh polka dot style accounts have literally no meaning uh because all the signature checking it's using the ethereum sort of algorithm so cool all right um so like i mentioned before the important thing about moomim is also the kind of theorem right and one of the
things that i like ethereum the most is it's the composability right so the idea that you can all these projects that are deployed on ethereum can work with each other you can interact with all of them in a single transaction atomically on the blockchain right so they can if they want they can all work together in sort of like in this composable fashion without needing like permission right is it you cannot grab your like instagram picture and then well you can because now it's from facebook but you know what i mean it's like they're like this barrier sometimes in the web 2 world that it's not really true on the web3 world and so one thing if you think about it is that you have limitless combinations right i think i really like battalion when he talks about d5 it's like he never expected sort of like what
happened with ethereum to happen it's like because there's so many combinations possible that it's not really like easy to see and no one knows what's going to happen on ethereum in three years right it's super difficult because of limitless combinations basically and so one of the things we noticed is that to be able to replicate this on moonbeam one of the first things that developers asked for was tooling right is that we need the tools to build on moonbeam and so that's why on moonbeam you if you want the graph you have the graph if you want covalent for indexing you have covalent you have changling for example for oracles you have metamask ledger and tresor those wallets which probably ledger is the one that is more more more famous among these wallets or metamask you can use them on moonbeam from day
one um you have etherscan which is another dependency that developers were screaming for it's like we need an advanced block explorer uh you have a nosy safe multi-sig fork so you have multi-sig wallets as secure as the true noses multisig contracts pinata truffle hard hat remix ether.js and and for interoperability we provide uh that's why i put the polka dot logo here because this is xcm but we also have good partnerships with axler and nomad just to make sure that you can also interoperate outside of the polka dot ecosystem right and we're going to talk about this in a little bit uh further so moomin right so we i like to say that moomin provides interoperable
composability powered by the xcm and the gmp protocols gmp's general message passing protocol right because if you think about it xtm which is this polka dot like sort of way that you can talk with each other it's it's bounded to polka dot only right and we want to make make sure that moonbeam is not only bounded to polka dot it's also be able to connect with avox with ethereum and so that's why we're also like leaning quite a lot in gmp protocols like axler and nomad and gmp's general message passing by the way all right so i talked about evm with expanded features and this is something that not a lot of developers know and and this is one of the features that i really like the most because sometimes the evm is quite limited and we provide sort of extra functionalities
so um what i meant is that we have some pre-compiled contracts right and the cool thing about the pre-compiled contracts is that it allows you to access sort of like substrate native features so so features that are not really inside of the evm from the ethereum api right so one of the examples is the staking precompile which allows you to do the staking which is this you know moviemaster proof of state network you can actually if you've ever used moonbeam and this is the the dap you're actually doing staking which is not an evm feature but you can see that you're signing the transaction with metamask right so users don't really need to understand oh jesus this is a substrate feature i should go to polka dot js abscess they just use ethereum like they would in any other network right and so
that's why you can actually stake with ledger with tresor and all this another pre-compile we can offer and this is basically for developers developer can can access this taking features from a solidity interface the same way with the democracy pre-compile they can access on-chain governance methods from a solidity interface and this allowed for example this this app which is called poke assembly which is like a forum for for governance decisions they can actually vote on it using metamask once again and this is a feature that is only available on moonbeam because you have these sort of precompiled this is the one that it probably is the weirdest weirdest one but it's one that makes a lot of sense is that the the glimmer token or the mover token which
is the native token of moomim and moon river you can actually act like interact with it like an erc20 token what this means is that you can add even though you have glimmer in metamask as a native token you can actually add it also as an erc20 token and so it looks weird because you have glimmer here but you also have sort of like the near c20 version of glimmer down there and it's the same thing it's not like we have like a wrapped version of glimmer which is what all the chains are doing right you have eth you have wrapped eath you have matic you have wrapmatic right in here it's the same token basically you're accessing the substrate functions that allows you to transfer balance but from the ethereum api right so metamask will see the transfer function so we'll just transfer this erc20
this precompile it's it's super exciting and we launched it recently and once again like the idea for you to understand is that pre-compilers are extending the avm functionality because that allows developers to access features that are not native from the evm and this is one that allows you to batch evm calls into one single transaction right so you can have the typical example i like i like to give is that um we have sort of like a demo that i did the other day where you have for example a dex a dex needs to ask you for approval to spend your erc20s and then you have to swap it right it's a two-step process every time if you go to any decks the first time that you interact with it approve and then and then
ascend if they've implemented some eip712 you're actually signing a message and then swapping but it's still a two-step action with the patch pre-compiled what you can do is that you can batch the approve and the swap uh string six or transactions in one single ethereum call so the cool thing is that we expect i don't i don't know if you ever guys use ocean protocol but i used it once and you have to sign like six transactions in order to do like a swap it was super crazy i mean and i i know this has a meaning like they you have to do six transactions because there's a purpose but imagine you can just like batch them all into one single transaction the ux will be a hundred times better right and so this was allows ethereum developers to ask access this feature
and then we have a bunch more um if you participated in the maneuver crowd loans uh you actually claimed the rewards using once again metamask so you know this was uh thanks to the problem pre-compile we have a call permit that is still being tested this will allow any any evm action to be gasless right so this is a very interesting for projects like economy and then we have some more if you're interested we can go into more detail all right that's it that's about moonbeam that's polka dot let's talk about interoperability which is the main topic of the workshop right and let's talk about xcm so xcm um the way that i like to incorrectly explain it because this is not correct but i said like a good
analogy is that it's it's a format right it's a format of a message right so i like to say that in emails right you always say hey alice how you doing the introduction and then you have how's it going how was your vacation you have sort of like a body and then you have a good i could buy a sentence right it's xcm is similar like that it has to have a very specific format with a set of instructions and this is the most important thing and this set of instructions the combination of a series of instructions is what you're actually going to result in an action right so basically the idea is that xcm is very general very general very extensive because it's not bounded by a bunch of rules it's just a way that you have to write this message
and then the there's a virtual machine once again this is incorrect it's not similar to the evm but it's you can think of it as an evm that will actually interpret this and execute this instructions that are given by the xcm right so let's say you have a message that is saying hey alberto walk 10 step towards the door the next instruction is flick the switch and then the next function is walk back right this virtual machine let's say it's my brain is going to actually in understand those instructions and they're going to execute them right and so um then you have the communication channels what is what allows chains to actually talk with each other and the channels are unidirectional right so let's say um mummy wants to talk with akala which is
another parrot chain and ecosystem there has to be a channel from moonbeam to a kala and a channel from akala to mumbi right and any parachuting that is already connected to polka dot or kusama it already has a channel with it you know it does you don't have to open a channel with the relay chain and then there are different transport protocols right so the transport protocols is the way the messages are moved so if it's from the parachain to polka dot then it's ump if it's from the polka dot to moonbeam it's dmp and between parachains is either xcmp or hrmp that just depends right now on the technology so the instructions like i said before um it's what allows stuff to happen right so a combination and you can find all the instructions in
the top right corner that's like a parity uh xcm sort of repo and and the combination of instructions well it's what allows you to do stuff in the other chain right so for example these three instructions what they do is that they we draw assets from a special account in the in the target chain let's say i'm talking with polka dot right so i'm telling polka hey polkadot i want to remove x amount of tokens from a special account on pokedot with those account with those tokens i want to buy some execution time of your block right so the block has x amount of seconds and then i want to buy 0.01 seconds to execute something and i want you to execute this so these are the three instructions that polka dot will
understand through their xcmvm and we'll say okay okay so what you want me to do is to do a balance transfer right so these three instructions for example are quite commonly used to open communication channels or to remotely transact with other chains and another important topic is is weight and this is not a specific to xcm this is the way you're familiar with gas on ethereum everyone's familiar with gas and ethereum this is sort of the the gas analogy an analog analogy thing of polka dot and substrate in general it's called weight and weight is defined as the time in picoseconds that that transaction will take to execute okay and it's not the
same if you execute it on an intel pentium from 2000 that you do it within the latest i7 you know machine and so the idea is that parity decides standard hardware so like i7 from 2020 this amount of ram this this hard drive ssd with the specs and then i'm going to see how much time my transaction takes in pack picoseconds to execute all right and so that's what you see on the right-hand side different sort of xcm instructions how long they take in in sort of like picoseconds and how much they cost in dot alright the main difference here that you can notice right away is that for example this xcm instruction takes one billion weight units on polka dot but takes roughly like a tenth of
that on kusama right and this is because parity has not actually measured the time that this instruction takes on polka dot on time but they did measure it on kusama right so this is cool what it's called benchmarking so they they benchmark the the amount of time that we draw us it takes on kusama but they've not done it in polka dots so they just say okay because we don't know we're just gonna just we're gonna put a large number just to make sure that people cannot cheat the system right and so that's why you see a huge gap in sort of weight the idea is that in the future they will do it and they will put a more realistic number here if you actually check for example how much time it takes to execute the buy execution it's way less than the
withdrawal asset but on polka dot is exactly the same which is not really true it's the same for a movement right withdrawing using this instruction actually costs 200 million weights but you buy execution is the same because we have not benchmarked these instructions yet what's important to understand then is that to execute these three instructions we would need three three billion uh weight units on pokedot quite a bit less on kusama and 600 million weight units on on moonbeam so but please understand that weight is not xcm specific it's any transaction even even evm transactions actually use weight and what we do in moomim is that we have sort of like a gas to weight mapping we know that 12 million gas
units it's more or less this amount of weight because the ebm works with gas but substrate the underlying technology works with weight okay cool so this is the current status of xcm channels right so this is the communication channels that i spoke before and what you can see is pretty pretty cool because in kusama you have i i don't know like there's a lot but there's all these pair chains are talking with each other and once again the the best three words ever natively the centralized and and like in a native fashion basically right they don't need to trust anyone trustless decentralized natively right i think do we need the mic all right no worries yeah go ahead
um yeah all right no worries all right the question was what was the legend on the lines if that some of their are dotted i mean the picture is not really great but some of them are dotted and some of them are red so the idea is that a channel has basically three steps right you need to propose it and the other person needs to accept it and the third step is to propose it back and then so there's actually four steps right so i mean let's focus for example on pishu you can see that there are two lines right and blue ones that is because there's one line going to for example karua and another line coming back from korea to pishu the the red dotted lines is that their proposals right so for example litmus
when i took this picture litmus actually proposed the channel to moon river and we have not accepted it and we've not proposed back i think if you check this picture right now is we actually have the channel but that is why there is differences right you can see that there are many chains actually communicating already on moon river um and then in polka dot we have a lot less chain because xcm is newer in polka dot it just launched like a couple months ago i forgot to add something here that i found out the other day is that kusama has a seven-day average of 100 million dollars in value that is being transferred through xcm and polkadot has roughly 450 million dollars in value transferred in seven days which is pretty crazy and once again this is natively right
there's no re-layers nothing in the middle like that it's assuring that you have these values somewhere else all right um now we're going to talk about xcm but but specific to moomin what is moomim doing with xcm right and so the first thing that uh i'm going to talk about the xcm use cases because that you have to understand what like what what is moving using xcm for the first one once again is token transfer this is like you know the typical like 101 because everyone wants to do token transfers and so this is how token transfers works in general this is not a specific to moonbeam but the idea is that when you want to move dots let's say for example to moonbeam what happens is that moonbeam owns an account on pokedot and this account is not held by
one person it's like i have the keys in my pocket it's owned by the entire pair chain so the only way that the parachain can actually move funds out of this account is through governance right so it's not easy it's not it's not meant to be easy the idea is that this account is very very secured it's not a smart contract it's a native account that the perishing holds and so the idea is that the the first xcm instruction that is sent in this xcm message is this one right here that is basically say okay grab this tokens that you want to transfer and put them in this special account and this xcm instruction actually has a field where you can put the other xcm instructions that you want to send with the message and these these xcm instructions are going to be sent to the destination
account okay so sorry to the destination para chain so it's like this xcm instruction has more xcm instructions that are going to be sent automatically to whatever account you're sending the tokens to so if this is a moombi special account this message is going to be sent to moombim so that that is why it's like atomic it's it's not like yeah yeah you can send these tokens to a kala but the message is going to be sent to moombim it's all in one go and so basically what's going to happen on moonbeam is that you're going to have these instructions right here and like i said a combination of these instructions what they do let me finish and then i'll have your question alright the combinations of these instructions what they do is that okay i know that i got these instructions because i i have this
instruction right here so i can check that i have the tokens in the special account and this last instruction right here what it's doing is that i'm going to actually mint a representation that we call xc20 which is like the representation of dot on moonbeam and then i'm going to transfer it to a destination account that i was defined in the general xcm message okay so there's a person with a question there hello hello oh excellent so if you're doing a transfer and bundle instructions so it's all executed atomically if the instructions are unable to execute does the transfer get reverted yeah that's a good question like one of
the things about xcm that people need to be aware of is that it's not really atomic what i meant atomic is that basically this instruction allows you to append more xcm instructions but if the xcm message is not really well constructed what's going to happen is that the tokens are going to get locked in sort of like a status that can be only withdrawn from a special like governance sort of proposal right so that is why developers always need to test axiom stuff on test sets and stuff because if they don't really build the axia messages correctly it could it could fail depending on how you build it it could fail on polka dot and that's going to be reverted fine but if for example right the message was fine here and it fails here the tokens are going to be logged on polka dot
right so i mean there's there's certain guarantees that you cannot be given because it's sort of like a it's not an async sort of thing right i mean it's not that oh i'm going to check to see if this works and then i'm going to do it here it just it goes in one go right and this is the same with bridges at the end right you you cannot really verify that the execution is going to work even though you can estimate it and so on but yeah so the second use case which is it's really cool because you're probably familiar with lido and this is what lido is doing to provide sort of like liquid dots taking and liquid ksm staking it's called remote execution right and and we provide once again a special pre-compile so the pre-compiles if you're not figure it out by now is that
the way that we actually extend sort of like these these polka dot native features or substrate native features to the to the evm and so the idea is that you can trustly execute on a remote chain in this case lido is doing liquid dot and ksm staking on polka dot and kusama and so a user it's it's interacting with their evm wallet right so metamask ledger and well actually what they do is that they sign a transaction with the lidar contracts and so the lighter contracts give you the liquid staking version of of the the the asset in this case is the st ksm and they give it to the user but the lidar contracts also interact with this special sort of like pre-compile instruction
that is going to do a remote call on the kusama chain so this this pre-compile will build an xcm message and then we'll send it to kusama and we'll tell kusama hey buddy can you actually stake x amount of tokens whatever tokens the the you know the user staked uh can you stick it to x y z validator on kusama but if you think think about what's happening here right you have a user on moon river directly staking tokens on kusama and once again natively decentralized and trustlessly right this is true interoperability happening here and this is how aleido is doing it and so it's really cool to see for me honestly this is the first true interoperable action because remote transfers or token
transfers are like boring at this stage right and so this is really cool because i don't know if any of you have stake tokens on pokedot but i mean until one week ago when they launched a new interface it was it was terrible like the user experience was terrible and lighter just like you go to lido you put i want to take five click stake and that's it like everything is done for you you don't have to worry about anything and it's just how it's supposed to be right and we're going to see that you know the idea of interoperability five minutes i have until 12 30. it was 12 25 yeah all right sorry okay because i also have to do the work so yeah i mean this is what true
interoperability is all right and the last one we're working on right now is remote evm calls so this is a way that other pair chains in the ecosystem can remotely call the evm this is very very new this is you know it's super exciting but we there's still a lot of questions that need to be answered but this is the way that we actually we expect it in the future right so for example other projects like centrifuge you know they want to call our evm to do something and they can do it via xcm so um i want to talk about xc20s because we're actually going to talk like we're going to use xc20s on on polka dot on the demo and so the idea of xc20s is that substrate assets are the ones that are interoperable right i mean i cannot really send an erc20 token that i have
to any other perishing in the ecosystem so the way that we actually did it on moomim is that we have sort of like an erc20 interface on top of the xc20s so that developers can actually access the the xc20s through the regular tools they can add for example dot as xc dot they can add it to metamask and they can you know do with like any other erc20 you can transfer it you can do whatever right so that is the cool thing about xc20 is that it allows these substrate assets that can move around you can add it to any evm dap or anything because it's an erc20 in the eyes of moonbeam it's a near c20 so we have seen for example um dexes or lending protocols on moonbeam you know adding sort of xc dot to their lending
pools or to their like farming pools and so on um and this is an this is an example and this we're gonna do it actually on the on the workshop so you could this is a moomimum tab and if you can see here there's a button called add to metamask right right behind basically the metamask and this will add dot as xc dot to metamask as a new c20 token and this is the current status of of xc20s on moon river you can see that we have roughly 74 000 ksms a almost 3.8 million remarks which is a really cool nft project and we have more and you know in pokedot we have a little bit less assets because it's newer but one really cool thing is that we surpass a million dollars uh as xc20s i think
last week or so so it's pretty exciting to see how these tokens have moved throughout the ecosystem and this is the last slide before we go into the the main part of the demo is connected contacts so the idea of connected contracts is that we want to be make moving sort of like an interoperability hub right i think we're positioned in a very nice way so that you know we can we can use the specialized chains inside polka dot to talk with each other but you can also have sort of gmp protocols like axler and nomad communicating moving to other chains in the ecosystem like ethereum cosmos and avalanche right and so the idea is that developers have to work really hard in making sure that these sort of like interoperability stuff are hidden from the user right remember the
lido example that i gave before and lido the user has no clue that he's from moon river doing an xtm message to kusama or to pokedot right so this is what we see the future you know moving towards to we have a really cool project called prime protocol and they're sort of like a maker they want to do sort of like a stable coin that's over collateralized but the deployment that they're gonna do is that they're gonna deploy everything to moonbeam but they're gonna have sort of like smaller pieces of logic and you each of these chains and sort of like you can actually deposit sort of like avax in avalanche to their protocol and then uh mint the stable coin on ethereum right and the whole logic is going to live on mumbi so they're going to rely on on interoperability protocols and but
the cool part is that you actually have all the logic in one chain and it's not like sushi swap that they've deployed to 12 chains or something and they have the same contracts on all the chains and they have to maintain it they have to have communities there it's a lot more work right the idea here is that you have everything centralized so it's easier to maintain you don't have the liquidities as for mac as fragmented and so on so this is the idea of smart contracts that you have sort of like interoperability within polka dot but also outside of polka dot and movie has a special position there because it's very well positioned for evm projects and so on so for the xcm demo we have to understand some really important concepts that it's very specific to xcm so that's why i wanted to bring them up
and the first one is multi locations right everything in xcm is done through multi locations and multi multilocations are a way to represent something in the ecosystem right the important i this was actually uh you know this idea was given to me by a colleague it's like you can think of it as folder paths in in linux right so let's say you're in the data folder and you want to go to the pictures folder you can just go up and then go down to the pictures folder right so the idea is that you have an origin and you have a destination right and so in multilocations for example are always expressed relative to an origin and like i said before can represent anything in the chain and they're represented by two parameters a parent and an interior the parent is how many
hops are you doing up so how many levels are you moving to an upper folder and the interior is in that specific folder that you are targeting where are you going where where are you heading to okay so let's do some examples so you get familiar with multi locations let's say we're in polka dot and the way that polka dot sees its own block chain so i'm in polka dot and i want to see polka dot is by saying parents zero because i'm not moving up and interior here so interior can have either here or x1 x2 which is how many fields you need to define where you're going it'll make sense when we see some examples so let's say i want to represent an account on polka dot right so the appearance will be zero because i'm not
moving up and the interior will be x1 because i need only one field to define an account and that field is account id 32 which is basically the polka dot account okay if i want to move to another para chain let's say akala i'm doing once again parents 0 because i'm not moving up i'm moving down and in interior i want to define a field called the parachain id these fields it's not that i'm creating themselves they're a list of fields that you can define and in this case the perichain id is sort of like the chain ids and it's especially i i an id that a perichine has that is unique in the network if i want to define uh from polka dot i want to go to alice on akala i have to
use x2 because i need two fields to define alice's account one is which pair chain am i looking for and the other one is is what is the actual account that i need to target right on moonbeam it's very similar right you have for example if you want to target the pair chain you can do perichine id and the main difference for alice with another account is that we use ethereum style accounts right this is not uh polka dot accounts this is ethereum style accounts let's say that from polkadot you want to target an asset that we have on moonbeam right the idea is that that asset lives under a pallet which is a specific sort of logic let's say it's like a smart contract but but not and so basically you can say okay i want
to target moomin parachain perishing id the following let's say a smart contract even though it's not a smart contract but it's a palette the following palette and the following asset right so you you're targeting a token inside boom beam inside polka dot right so this is this is a three-step process in this case all right if we're standing on moonbeam oh sorry if we're standing in moonbeam right now the story is a little bit different because if we want to target an account we don't need to specify the parachain id anymore we're already there so we just put the account and the same for the asset right so we it's the same as before but we removed the parachain id but now if we're targeting polka dot the main difference here is that we're
saying parents one because we're hopping to a higher level right we're in the in the subfolder we want to go to the mother folder load the parent folder right so we have to go one step up and then for akala it's sort of similar the main difference here is that that we need to make sure that we we go through polka dot and that's why we have to put parents one in both of these cases all right so that's basically the main difference all right so for the for today's demo that is going to be somewhat brief we're going to use the x token pre-compile so the x token it's a way that we can send tokens from moomim to other parts of the ecosystem and so the the the pre-compile basically has a structure which is the multi-location that hopefully it's a little bit clearer now what a
multi-location is and we have two functions a transfer one and a transfer multi-asset we're going to use a transfer one because it's a little bit easier because we provide basically the xc20 token address so it's like an erc20 token address we provide the amount we're going to build the multi location to specify a destination account and we're going to provide the weight which you more or less know but we're going to put a very high number just not too worried about the weight okay and so basically this is the three steps that we're going to do and and we're yeah let's let's talk about the multilocation right so the idea of the multilocation is that it has a uint to specify the parents if we're going to do if we don't if we want to send xc dot to polka dot we're going one step up so parents need to be one right
because we're going to move from moomim to the parent folder which is polka dot and then the interior and solidity is built in a very specific with a very specific set of rules let's say all right and these rules are all specified in our documentation because you have to once you get familiar it makes sense but at the beginning you're like yeah this doesn't make a lot of sense right so basically the idea is that the interior is built with a bytes array okay and the the size of the bytes area determines whether it's here x1 x2 x3 x4 all right so if the bytes area is empty we're saying that we're we're calling it here if the bytes area is size 1 it's x1 if it's size 2 sx2 okay so this is
basically a definition here that we see in the in the in the table and then the first byte or the first two hexadecimal characters define what of these selectors are we actually selecting right so if the first byte it's zero zero we're actually doing a pair of chain id we're targeting a parrot chain id if we actually are zero one we're targeting a polka dot style account okay if we're doing zero two is that account index and three zero three is no meme style accounts all right so if you think about it if we're transferring xc dot to a polka dot account the way that the bytes interior will look like it's 0x01 because we're targeting a polka dot style account
now the account number in hexadecimal is not the encoded value and then this is a rule that you just have to trust me and that you have to put zero zero at the end and it's because we want to say that this is like any type of account it's not a polka dot type account it's an akusama account we just prefer to put any because it'll be more generic and more you know compatible with all type of accounts all right cool so um for this like little demo that i'm going to do i still have sort of like 10 minutes so that should be fine um you actually have to go to the dev token so this is this is a faucet that we have for dev tokens dev tokens is a test net token that we provide um we're gonna swap you can swap some
tokens we have a uni swap v2 fork so you can swap some depth tokens for xc units so xc units are like our dot so we have moonbase alpha which is our test net and we have like a polka dot on mumbai's alpha which tokens are called units all right and this is the erc20 token address of the xc unit so this is like xc dot address okay and then you can also click here if you want to go to like the poke.js apps the second explorer for our relay chain for for the relay chain of moonbase alpha some important stuff it's sort of like links of interest it's like how to connect metamask uh how to check poke.js apps so similar to this one but for moonbase alpha and the relay chain the x token solidity interface if you want to
interact with it uh this is ether scan on mumbai's alpha and remix you know remix right and this uh if i have time i'll show you how to build an xcm message on the relay chain to transfer tokens from the relay chain back to moonbase alpha all right so let's try this okay so the first step is that i have metamask you can see here metamask i'm connected to the testnet as you can see here moonbase alpha let me zoom in a little bit all right so you see that i'm connected to moonbase alpha this is alice alice has a bunch of dev tokens and you can see that alice has already five xe units so this is dot basically we have five dots on mumbai's alpha
if i want to have uh def i can you go to the faucet where you put in your address here very simple and then you click here and then you get some dev tokens if you need xc units which once again is like the dot representation you can go to this uni swap v2 fork that we deployed for demo purposes and you can see select here uh xc units and i want to swap one dev token and i'm going to get 7.4 xe units this is for demo purposes i mean this you're not going to farm or anything here no worries um and then the interesting part here is in remix right so if you have any questions built in the multilocation let me know but building the multilocation is probably the the most challenging task when you're going
to use the solidity interface all right so what we're going to do is that we're going to transfer one xe unit you can see here because we have uh basically this has 12 decimals so you can see you see here that i have three three three and three so this is one token with all the decimals similar to whey and ethereum all right uh the address of the token is this one like i showed before so i can actually go ahead and add this token to metamask which i already did so that's why i have it here this is the account that i'm going to transfer the tokens to and this is the amount of weight that i'm going to use for this transaction all right so if i want to build a multi location remember
that the multilocation is a structure and the first element is the parents right so if i'm going from moon base alpha to polka dot i have to provide parents being one because we're moving one level up right so the first element of a multilocation hopefully i think you can see it enough right so the first element of my multilocation is going to be one it's very very simple and then remember that the second element was the bytes interior right the bytes interior and if you remember the table the size of the bytes interior will tell you if it's x1 x2 x3 so in our case we need to if we go back to the presentation right and we go back to this slide um you can remember that we are in moonbeam oh wait let me let me actually
put it in presentation mode because it's a little bit small so you can see here if you remember we are in moonbeam well actually it's the next slide all right we are in moonbeam right and we want to target an account we want to target bob on the relay chain so we need to provide parents one interior x1 and the account of bob right and if you remember in the next sample that i provided basically here you have to say okay so i need to have a interior of one so though it's going to be one and then it's going to be basically zero x01 to define basically that we're targeting bob's address and then zero zero at the end okay so how this is going to look like
on remix even though like i said this is just a rule basically that you have to follow it's 0x01 then we're going to put bob's address this is one-handed so i'm going to put bob's address and then zero zero because there's this rule that we're saying okay this account bob's address it's in any type of account all right it's not it's not polka dot it's not moonbeam it's not kusama it should work with a polka dot type account but we prefer to make it extensible and generic all right so this is basically the multi-location this should work right i mean but if we want to for example test it out we can just grab the erc20 sorry the x tokens address which is this one right here
go to this tab in remix if you're not familiar with remix let me know but we can just click here inject web3 what this is going to do is that it's going to connect remix to moonbase alpha this is a chain id of moonbase alpha and then we can just load the contract down here by pasting the address and clicking in add address all right so we have here the i mean yeah it's probably you can see it fine hopefully so uh we're going to use a transfer function uh if you don't see this well this is currency address so the erc20 token or the xc20 token that we want to transfer the amount the multi-location that we just built and then the weight okay this is the weight that we want to provide for this transfer and what what is going to happen if you
think about it is that moon based alpha or moon beam let's let's talk about moon polka dot moomin has uh this xc dots right and what's going to happen is that it's going to burn these xc dots and it's going to transfer out of this special account that i mentioned the the dots back to the owner and that that is what we're going to see on the explorer all right so let me fill this information up so the address this is the token address the amount the destination which i hopefully did correctly because if it's not it's going to fail this is the multi-location and then the weight oops and then the weight which i'm going to
put here 1 billion like i said this is not this is like a lot more weight we're wasting money it's like you know you're putting more gas and so on but this should work so what i'm going to do is that i'm going to check that this is the account that i have i have this is the relay chain so this is polka dot and let's say in polka dot i have 11.9 dot right and what's going to happen is that alice which has basically five dots right is going to get deducted one dot and that other account is going to get one more dot and this is going to happen once again through xen i did something wrong i think what did i do wrong
zero one oh wait yeah i need to put this in an array sorry all right cool boom so now i have my metamaster in section once again this is like a regular metamask interaction and what's gonna happen is that if we go to polka dot js app so this is the explorer of polkadot we can actually check that when this transaction gets processed we're going to see an event this is like a block explorer we're going to see an event called assets burned this means that the five xe dots are being burned because they no longer exist on moonbeam and then on pokedot or the relay chain we're gonna see sort of
this thing being okay i'm gonna deposit this five tokens to whatever person i specified so you can see here i got assets burned this is the well sorry it was one not five so i basically burned one token on moonbase alpha and then on the relay chain which is polka dot in this case i have the xcm message was executed successfully so if i go into the xcm message at some point i'm going to have a balanced deposit from from the person to the do the account you can see that i alberta relay now got basically almost one it's not exactly one you can see because i'm using that that dot to pay for the fees to pay for xcm execution fees on polka dot right so
that's why you're not getting a return if i go to the account you can see that i have now 12.9 instead of 11.9 all right and once again this happened all natively we executed that call on moonbeam using solidity basically as an interface because we're always targeting ethereum developers for these sort of things all right i don't know if this anyone has any questions any comments you want to pass a mic thank you um yes if i understand correctly so you you send native message from one parachute for example to the layer 0.
then layer 0 will interpret this message and translate it in like order that he knows then you see the result on the blockchain and how on your side on munbin you know that it has been uh finally executed yeah that's a really great question and the problem is that you just send the xcm message right but you don't really need on movement you don't really need to know or understand that the message was executed right because once that block the moving block is finalized by the relay chain that that message was executed correctly or not it was executed to your eyes basically what's going to happen if that
if the message was not correctly built right it was incorrectly built that message is going to fail on polka dot but that is basically the developer's fault sort of like you know the message was not executed correctly right but from moonbeam side from from the perichain side if if the the the relay chain already finalized that block moomin can think that that method was successful so for that for a developer of adap what they need to do now is that they need to understand that this is a multi-chain world right so they need to not only check the message and they need to check it on polka dot as well and ensure that that message was correctly executed on polka dot and that's going to happen with any interoperable app right i mean you you cannot see blindly on movement say
okay this worked you're gonna have to see the action that you took on the destination chain was it successful or was not successful right so in in when you're talking about mono chain deployments it's a lot easier right a lot easier because if the smart contract interaction was successful on a theorem you wait 10 blocks and that's it right but in a multi-chain world it's it's a lot more complicated because you have multiple chains in concatenating with it i mean talking to each other and so you have to check finality on all the chains so all right any other question cool i mean yeah at this point i think i just make sense to stop here thanks a lot for attending
and yeah i'll be around a little bit if you have any other questions so thanks a lot