New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

ZetaChain 🛠️ Omnichain Contracts with ZetaChain - Denis Fadeev

ETHGlobalMon, Oct 9, 2023, 12:00 AM

Join Denis Fadeev from ZetaChain for a workshop titled "Omnichain Contracts with ZetaChain". Learn how to build omnichain dapps with ZetaChain by creating an omnichain contract that lets you do cross-chain calls and transfer value between blockchains. Thank you to everyone who joined us for ETHGlobal Paris 2023! Paris is the city of light and birthplace of many revolutions. Therefore we were thrilled to be back in one of the most buzzing and free-spirited cities in Europe for ETHGlobal Paris 2023. A lot has changed in the European ecosystem since the last time we hosted a hackathon in 2019. ----------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com

Transcript

foreign [Music] what is Zeta chain it's essentially an interoperability solution that lets developers build cross-chain dabs or as we call them Omni chain dabs so Zeta chain offers a solution for developers to just write a contract once deploy it to Zeta chain and this contract essentially has powers to manage assets on all the connected chains so for example if a user has an asset on bitcoin they can send BTC to a specific address in this BTC becomes available to the contract on the chain and your contract can perform logic and for example swap the token for another token and withdraw it back to a native chain so that's called omnichine contracts it's super easy to start building with uh with Zeta chain if the screen comes back alive I will even show you that but Zeta chain offers also an alternative way of building cross chain dapps and it's through cross chain messaging so cross-chain messaging is instead of deploying a single contract Tuesday to chain you deploy contracts to a bunch of different chains and they're using Zeta chains API to send messages with arbitrary data between chains so both Solutions have advantages um the advantage the main advantage of omni chain contracts is that it reduces it drastically reduces the complexity of the system that you're building so you just have one contract to worry about only States is only in one place so that's very that's very convenient from an architecture point of view so in depends so the question was should you deploy it to single chain or to all the chains or Zeta chain deploys the contract so it depends on which paths they're taking for Omni chain contract you would deploy it once to Zeta chain and that's it you don't need to do anything to any other chains it's just all works out of the box if you're using cross chain messaging you have to deploy it to all the chains you want to connect so right now four chains Zeta chain is in the tested phase four chains are connected more chains of course will follow but if you're using cross chain messaging you're deploying a contract on all four chains and you're also setting an interactor so you're basically telling um to each contract you're telling the counterparty contract address so that it knows which contract to talk to so it's a bit more involved from the architecture point of view but it's kind of a very well known solution basically right so if you if you have an existing application that needs to be augmented to become cross-chain you can use cross-stream messaging for like specific areas uh if you were to build something from scratch I would recommend looking into Omni chain contract first because it's just so much some clearance the the killer feature say the chain if anyone has questions let's just jump to questions I guess first which is weird before yeah go ahead so again it's like if only chain you just deploy one's cross-sheet messaging you deploy it to all the chains for cross-chain messaging you will be able to send messages between the chains you deploy your messaging contract to because um so for example Zeta chain at some point might support like 20 50 blockchains you might be interested only in three of them or like 10 of them so with cross stream messaging you have to explicitly deploy it to the contracts you're interested in so does that answer the question uh right now in the test net phase only four chains so that would be Bitcoin ethereum polygon BSC of course more chains will follow and Zeta chain is built on Cosmos Tech so um possibly it will be IBC compatible if you're familiar with Cosmos then this will connect it to even more chains and uh we are planning on iterating more evm blockchains and non-evm chains chains as well one of the advantages um so besides Omni chain contracts the advantages of Zeta chain include uh Bitcoin interoperability so not many solutions especially decentralized Solutions support Bitcoin out of the box so from from Bitcoin you can triggers more contracts on Zeta chain which is pretty cool and there's very little overhead and there's nothing you need to do on bitcoin you just um you just ask users to send tokens to a specific address and that triggers a contract call on say the chain and the other Advantage is that it's um uh there's no wrap assets so there are wrapped assets on Zeta chain when the process happens right when you deploy when you send tokens uh to a TSS address on a chain Z or C20 wrapped version of the original asset gets minted but only gets minted on Zeta chain for the purposes of swapping and working with it so it's like representations of the original acid on Zeta chain Okay cool so let's continue with with uh with the slides um so I talked about cross chain messaging omnichine contracts now I want to show how well basically easy it is so if you go to zayshane.com docs in the developer section you will see two sections Omni chain contracts and cross chain messaging so here is a complete example of an omni chain contract as you can see it's super simple like the only thing uh you need is um Z contract here a couple of imports and you need to implement on Cross chain call function this function gets called whenever tokens are sent to a specific address on any of the connected chains so for example if someone sends tokens to a TSS to a specific address on ethereum uh they um there are two paths these tokens might be just deposited into your contract on Zeta chain or if a user sends tokens and supplies arguments in the data field of the transaction um these arguments get passed to your contract as the message then you can decode the message Implement your logic for example this contract is super simple it just would withdraws the tokens to the same chain doesn't do much but it it shows you an example of how to trigger an omni chain contract and how to withdraw but you can of course swap to a different token and withdraw to a different chain or you can mint chain mint tokens or say the chain it's really up to your contract but the the logic is super simple token transfer on a connected chain triggers this this function call and that's it and then you can use your C20 which is an extension of ERC to withdraw the tokens back right now Omni chain contracts support native gas tokens as well as erc20 of course more asset types will be added later your C20 need to be whitelisted by the chain and this is not a centralized solution not a centralized decision uh but the blockchain is going to be very decentralized and people are gonna the community is is going to be voting on important decisions like which your C20 would want to uh whitelist if it's whitelisted a pool will be created internally on Zeta chain so that tokens can be swapped and so forth so as you can see there's not much to it um your contract just needs to implement one function that's that's it um with cross chain messaging it's also pretty straightforward so here you have a few things in your temple on first a function that will use Zeta chains connector API to send data so you just provide some helpful information like where do you want to send the message to the destination chain you need to provide things like gas and uh but most importantly you need to provide the message here is just a text hello world message but you can encode any kind of data you want and it will be processed once the message once the function gets cold um this will essentially trigger a process where an event has emitted on on the source chain Zeta chains validators they run nodes of all the connected chains and when they see a transaction happening they will vote on Zeta chain whether they've observed this transaction or not if enough votes are cast the transaction will come go through and will be processed by Zeta chain and on the recipient and you just Implement on Zeta message so if the transaction comes through you just handle it for example if it's a nft project you might want to lock the nft in the send message function right here you before connector send you will lock the nft you will mint an nft onset a message on the receiving chain and maybe send an acknowledgment back to burn the original nft if you if you got a new nft method right that that could be but again the architecture is up to you this is just a kind of low level uh primitive for you to be able to transfer Val uh to transfer value and data between all the connected chains you don't need to worry about Zeta chain here at all because data chain works as intermediary here so we have a lot of tutorials uh for for everything you can you can see a very simple cross chain Swap and just what is like 30 lines of code um withdraw tutorial um you can also um check out the Bitcoin tutorial as well not many projects support Bitcoin so that's pretty pretty interesting um what I'm going to show the last thing I'm going to show is uh basically how you would start so you would go to github.com we have a bunch of reposts here but I recommend just cloning the template so github.com Zeta chain slash template when you clone the templates you have something like this and it it doesn't have much but it Imports a bunch of helpful utilities so if you run npx heart hat you will get a bunch of helpful tools so for example if you need to connect create an account you just part hat accounts and it will create an account for you you can even save it so you can um yeah balances this is helpful because we're dealing with a bunch of chains so you need to know uh what kind of tokens you have so on the all the connected chains you can see native Zeta and zero C20 equivalents what is super helpful I think is how you get started building so you have a command hard hats um Omni chain and what this does is it accepts a name so let's call this contract withdraw and a bunch of um params like recipients data whatever from so what this will do is it will create a contract um that you just need to fill in the blanks right so it's it's it's all it's already there for you and you you you already have a deploy task so you don't need to worry about that and also a task to interact with it so you just executed one command to create a new contract then you can run um or tab compile now you can strongly deploy work so this is a normal chain contract here you always deploy it to Zeta test net and of course it doesn't do anything right you saw that there's a blank in the in the in the contract but uh and and boom you got the contract deployed and you can interact with it as well so like all the boilerplate code is here and um there are more tasks uh one more useful thing is if you're building with costume messaging we also have a task for this so npx hard hat messaging uh my contracts fubar and this will create a cross stream messaging contract instead and it has Foo and bar here so it already you can already compile it and deploy it to different chains let's do that it's slightly different because with cross stream messaging you deploy it to several chains so let's take early test net and by test net okay to compile it first thank you and what this will do is it will deploy the contract to all the chains you specified but also set interactors for all the contracts so that it will tell um the contract on Mumbai the address of the contract on Gurley so it kind of wires everything up together so you don't need to worry about that you just read the docs understand how it works and implement the logic of your contract and sometimes they want to send through this connector send Zeta chains API so I don't have much time for anything else I will be available as is the rest of the team downstairs at the booth so please do check out Zeta chain if you have questions more than happy to dig into any technical details if you're going to be building on we have a price for the hackathon more on the website but please do make sure that you're using data chains API and actually build something with cross chain messaging or only chain contracts that's very important and yeah good luck on the hackathon thank you foreign [Applause]

Automatic transcript — names and jargon may be misspelled.