Bridge any ERC 20 token with Unified Bridge - ETHGlobal Bangkok 2024
ETHGlobal·Thu, Oct 9, 2025, 12:00 AM
Join us for a workshop with Kenil Shah from Polygon titled, "Bridge any ERC 20 token with Unified Bridge." Learn how to bridge erc20 tokens or pass any cross chain message between chains connected to AggLayer using Unified Bridge. This workshops took place at ETHGlobal Bangkok, a 3-day hackathon held November 15 to 17 2024, that brought together the most skilled web3 developers, designers and product builders from all around the globe for a weekend-long adventure to advance the Ethereum ecosystem! ----------------- Follow us: https://x.com/ethglobal Check us out: https://ethglobal.com/ Email us at: hello@ethglobal.com
Transcript
yeah hey everyone um this is Kel I am a Dev support engineer at polygon labs and today this Workshop is regarding how you can Bridge your any erc20 assets across chains connected to Ager using unified Bridge um yeah Bridge any erc20 assets using unified Bridge uh and this is the whole architecture for that like before diving deep into this architecture um I I would I would just like to explain how exactly it will work on a on a high level overview so as soon as you so it's it's whole architecture where the unified Bridge contract plays an important role and unified Bridge contract is deployed on L1 as well as all the l2s that are connected to Ager and uh you can use those unified Bridge contracts and all these l2s while bridging assets so uh it's it's a copy of instance of all this L2 l2s uh sorry of these contracts on l2s so yeah let's that's the whole architecture and U yeah let's dive deep into it yeah this is the whole flow on how will your trans transaction go through from each and every uh Merk Leaf nodes as well as meral tree roots uh so let's say as soon as you bridge your assets uh it it will basically you know add a leaf to the local exit route tree it's it's just a basic Merkel tree with 2 ra to 32 Merkel Leaf nodes and as soon as you bridge your asset it will uh so Bridge asset will contain all the information regarding your destination chain your destination address uh um your uh token amount token address Etc so this information will actually be added into this moral Leaf node and um it it will basically hash the mor Leaf nodes two two of the mar Leaf nodes and it will create a hash for that and essentially it will create a local exit Road tree uh on the L2 so basically uh it just a hashing of leaf notes on every local exit rout tree of rollups and uh at the end it will update the global exit route tree node which is on the L1 and uh this is how exactly you will verify that my asset is being bridged from l2s to other l2s or just from L1 to L2 so yeah so as soon as you bridge your asset it will add as a lift node and it will add it to the merkal uh tree to the local of the local exit route tree and it will update the local exit route as soon as a new bridge asset Leaf node has been added and next this local exit route tree uh not the tree but this local exit R it uh it lies on the L2 uh or or your or any uh layer to chains connected to a layer so it just lies on the L2 but as of now your L1 or your destination L2 doesn't know like what is exactly happening so basically you actually need to update the uh second route that is rollup exit route uh what is rollup exit route exactly so basically you have five layer TOS for example and there is a single rollup exit route for all these five layer l2s and uh as soon as you know so it's something like uh as soon as you add Leaf nodes to multiple uh local exit tree roots it will update multiple local exit tree routs right but there is only one route which is called rollup exit route and it will update that rollup exit route to get synced with all the uh data and you know to basically uh be updated of the current state of the uh blockchain so it will it will just update the rollup exit route it is on the polygon rollup manager. Soul contract which which lies on L1 that is main net and this again is just a rollup exit route so it contains uh you can say essentially that it contains the state proof or Merle proof of all the l2s but not we have still yet to have the uh main net exit route here uh which also which essentially contains all the information of all the rollups as well as L1 so uh and here you actually get the data of my bridge asset which is which is added on on the layer two so yeah here we come so as soon as we add this uh rollup exit route um as as soon as it updates the rollup exit route and uh eventually it also updates the global exit route now what is global exit route Global exit route is a roote node of for example if you take a small example Global exit route is a root node of two lifts that is a rollup exit route and mainnet exit route and Main net exit route is basically uh root of all the bridge message or Bridge asset Leaf nodes of the main net or or all the or of the L1 and this rollup exit route is basically root of all the leaf notes of all the local exit roots of all the rollups it's pretty confusing uh but all you need to know is like it's just uh it's just p putting a Merkle proof on the L1 so that any L2 can read it and actually claim the asset on the destination chain um so like it's it's just a proof a Merle proof that says that hey this asset was bred on the source chain now it's ready to claim please claim on the destination chain so it's it essentially just says that so yeah this is the whole architecture I wouldn't I I would not deep dive into it but you just need to keep in mind that Global exit route is the route that you need to uh get to claim the asset on the destination chain because we are waiting for the uh you know L1 finality here so yeah um here are the code examples uh I just uh go over through one code I'm not sure if it if it will work because uh my PC is giving some issues my laptop is giving some issues so I I just try it out by cloning my repository here yeah uh this is a small example where you uh Bridge uh we will create a first token uh erc20 token named egg and we will deploy that token contract on uh sepolia and then we will min that token to our address we'll approve that token to this unified Bridge contract address and then we will try to bridge it uh from sepolia to polygon zkm Cardona so yeah here we go oh I hope that is visible um yeah I okay I been needing a couple of things I think I think this might take time and I think we are short on time let's let's try uh we can um uh let's uh so uh probably let's just try to understand the code as of now because uh to gather some API keys for SE as well as for polygon zvm uh it might take some time and yeah so let's go ahead and just first understand the code uh I don't think we have much time uh yeah I think we have 30 minutes I think we can do that let's go uh for uh let's go ahead and grab some API keys to connect to our seia as well as polygon zqm Cardona Network let's go ahead and grab some end points uh as of now yeah I'll just copy this URL and paste it here I'll rename this file to EnV yeah uh I just grab this API key and also paste it over here since we are using polygon zkm API of alchemy uh yeah I think I think we are good to go let's go ahead and see if we have some funds on yeah I think this should be enough uh so let's go ahead and deploy our Oken contract this is a simple contract as you can see here it's just ECT toen contract with a M functionality so it's a simple contract let's just deploy it deploy yeah and CJs yeah what it will do is it will just deploy this contract on sapoia network uh so as you oh no um I I actually need to define the network first because we have a couple of networks in the harded config we have sapoia we have Cardon as well as AAR uh so I think okay it will throw us some some error but yeah we can run the command again so essentially it will just deploy this contract to sepolia network uh oh strange it deployed uh I think I need to I think it deployed on on a local harded chain so let's go ahead and deploy it on sapoia network yeah uh and then we will try to yeah here we are so I just copy this contract address which is of EG token contract and uh in the Bridget file I have a couple of things uh I I'll just try to explain it yeah this is a token token address that we need to bridge from Source chain that is sapoia to polygon zkm Cardona so I just paste this token address here uh this is a destination address a destination address could be anything uh any evm address and yeah so basically we have an array uh uh the so we need an ID uh to indicate what is the destination chain as well as what is the source chain but in this case in our case it is not the chain ID but it is a separate network ID that we have created so uh for sepolia it's zero for uh AAR zkm uh sorry for polygon zkm it's one and for AAR it's two uh so yeah just to indicate uh this network IDs and um yeah so here is a source Network array I have just created an array to you know um to bridge asset on the source chain as well as to claim asset on the destination chain you need a provider for both of them to interact with the contract of bridge asset so of unified Bridge uh so uh we need we need provider for both of them so I just I have just defined it here uh we are getting private key from EnV we are getting um unified so unified Bridge contract ending in 52 it's constant on every single chain let it be um sapoia or polygon Z KVM it's constant on all the all these chains uh now and uh yeah so Source network ID is basically zero for for our case we just deployed the contract on sepolia so it's zero and we'll be bridging this asset to the destination network uh with having ID one that is polygon zkm Cardona so basically yeah uh this is destination network ID uh destination Network address token contract address token amount that we want to Bridge and uh yeah I think that's that's it now what we do is we just create a provider we just create a wallet uh essentially to sign the transaction and then we create a bridge contract instance uh that that is Unified Bridge contract instance we provide unified Bridge contract address unified Bridge uh ABI as well as the wallet to sign sign the UniFi Bridge contract address sorry uh transaction and here we have erc20 token contract instance that is to be able to Mint those tokens first we will just first mint those tokens to our address and we will approve those tokens to this contract and then we'll try to brid these assets so uh I just created this erc20 token contract asset uh uh instance uh I'll just probably write here uh the token address and yes I think that should work and and again I'll just remove this and I'll write token address here as well um yeah I just remove this as well and write token amount the amount of token that we want to M same goes for here token amount here I just remove this and I'll replace it with unified Bridge contract address yes so essentially what we are doing here is uh we are first minting those tokens to our address that is that is the oh uh my bad this should not be token address but this should be our address so I'll just copy my address and paste it here in the string format yeah so first we're minting those tokens the egg tokens uh along with the token amount to this address that is my address and the token amount is basically uh so it's 18 decimal token so uh since we need to Mint one token let's put 18 zeros here first I'm not sure how many it was yeah now we have 18 decimals here uh and I think we are good to go yes uh token approve Bridge contract and yes so let's first try to so this uh running the script will essentially mend those tokens to this address and with the token amount as one uh and it will also approve the uh unified Bridge contract to spend those tokens on our behalf so yeah let's go ahead and try to see if this works uh I think it did I think so let me just uh oh I forgot to wait for this transaction to actually go through because uh menting and approving uh takes some time so I would just wait for this transaction a wait uh meant dot I'll just wait for one block as of now and a wait approve transaction. weit let's let's wait for two blocks to be sure that the transaction actually went through and is actually included into the block and uh yeah that's pretty much it I'll I'll I'll uh go over through this code later on once we actually bridge this transaction once we actually uh you know M this token to our address let's see if it goes [Music] through uh yeah it will just console log out the whole object uh of of the transaction and we will just pick out this transaction and see on the seoa chain that it actually you know um went through uh yeah by the time destination network ID is again so here uh this bridge contract instance contains a bridge asset function which actually carries out the bridge transaction and there are six things that you need to pass in that is destination network ID destination address token amount token address and force update Global exit route so what this force update GL Global exit route does is if you put it as stro it will uh immediately update the global exit route on the L1 so otherwise it will do it periodically so if you want to force update it uh you can do that too but it will uh it will actually take some some more gas fees but not that not that much but yeah so it will update the force Global exit rout on the L1 so that you know um you don't have to wait for this uh um uh for periodically so there is a service API which is periodically updating this Force Global exit route on the L1 and uh the L2 is reading this data and actually sees if the you know if the transaction is ready to be claimed so yeah you can do that by just putting the flag as true yeah as you can see oh uh yeah tokens uh just brid transaction just went through I just copy this address uh and see on Portal do polygon do technology I just connect my wallet and uh yeah I'll switch to the test net to sapoia and when I go to transactions yeah here we are uh so yeah transaction was uh Bridge from sapoia to Cardona it takes 30 minutes to land into Cardona test net so yeah and you can see so we just bridged for one token and yeah um yeah it's done and for Cardon zkm you don't need to claim the assets uh because we are running an autoc claiming service in the in the you can see as back end but let's say if you are uh doing otherwise like if you are bridging asset from Cardona to seia you need to run this claim asset function by yourself it's also in the code itself so it what it does is a high level overview is it just you know uh fetches all the Merkel proofs that we just talked about in the in the first part it fetches the meral proof and verifies if this assets are ready to be claimed and then it claims the asset once we call the claim asset function on the destination contract that is again uh the bridge contract on the destination chain yeah that's it thank you so much
Automatic transcript — names and jargon may be misspelled.