Original title: "Celer Inter-chain Message Framework: the Paradigm Shift for Building and Using Multi-blockchain dApps"
Original source: Celer Network
Original compilation: CelerNetwork Technical Community

Celer Inter-chain Message (Celer Inter-chain Message, hereinafter referred to as Celer IM) has been officially launched and launched on the testnet.
Celer IM fundamentally changes the development and usage paradigm of multi-chain dApps. Developers can now develop dApps that share liquidity and program state across multiple chains through Celer IM. Users can enjoy liquidity and applications on multiple blockchain ecosystems with one click through Celer IM without having to manually cross and switch between multiple blockchains for complex interactions.
Celer IM enables cross-chain composability, enabling a range of new Mode "native cross-chain dApp". Examples are as follows:
DEX will allow users to exchange assets across multiple chains in one transaction
p>
· Yield aggregator will allow users to manage multi-chain assets from one chain
· Lending protocol can allow users to provide collateral on one chain, Lending assets on completely different chains
·DAO governance protocol allows a unified multi-chain governance mechanism without the need to move assets between different chains
· NFT marketplace where users from one chain can bid on NFT auctions on a completely different chain
·Metaverse game , users can seamlessly interact with virtual items of various chains in the game
·New cross-chain asset bridge , in fact cBridge can be seen as an asset bridge built on Celer IM
Almost every dApps deployed on multiple chains can benefit from using the Celer IM framework.
The Celer IM framework is very easy to use, allowing "plug and play" upgrades , without modifying the deployed code. For example, Uniswap and Sushiswap only need a simple plug-in contract can be transformed into a native cross-chain DEX. (Click here to watch the demo video)
In In this demonstration, users of Sushiswap can exchange ETH on Arbitrum for BNB of BSC with just one operation. Throughout the Celer IM system, the following steps are automated and decentralized:
· Swap ETH on Arbitrum for USDT in Sushiswap
· Bridge USDT from Arbitrum to BSC
< /p>
· Exchange bridged USDT for BNB on BSC
And publish demo program, Development documents, smart contract framework and Sample application code. We are actively looking for developer partners to jointly create powerful and user-friendly native cross-chain dApps. If you are interested in cooperation, please contact us.
Currently common The practice of developing multi-chain dApps is by simply duplicating the same code on multiple chains. The liquidity, application logic, and state of these dApps on different chains are completely isolated. In fact, apart from UI and assets, there is nothing shared between these dApps.
This method usually has the disadvantages of low liquidity efficiency, state fragmentation and user experience degradation question. By implementing cross-chain contract calls and messaging, Celer IM enables users to enjoy higher liquidity efficiency and unified application logic through "one-click operation", so that these dApps based on Celer IM can mine the true value of the multi-chain blockchain world. potential.
Give some examples.
Today, a multi-chain DEX must build liquidity pools for the same key asset pairs on each chain it is deployed on. Therefore, the DEX has to create liquidity incentives for these asset pairs on all these different chains. While the aggregate liquidity across all chains may be quite high, the depth of liquidity per pool on each chain is actually quite fragmented. Unfortunately, this creates high slippage, which affects the overall trading experience. Also, if a user wants to trade an asset that has deep liquidity on a different chain, he has to manually convert it on the original chain, use a separate fund bridge application, and then switch to another chain for the final swap.
DEX built with Celer IM can automatically transfer transactions to Deep liquidity pool, which significantly improves the trading experience. Through this innovation, DEX projects can gather the liquidity incentives of a certain pair of tokens in the same pool, thereby creating deeper liquidity with low slippage.
Celer IM implements a new type of inter-chain lending, users can seamlessly transfer their collateral from a liquidity pool on one chain to a pool on another. They can then directly borrow assets on the new chain. With this feature, users will have a simple and clean user experience that allows them to do what they need to do without ever leaving the loan app.
Today, if users want to participate in NFT auctions, they must have funds on the blockchain where the NFT is located. But often there are people who want to participate in the auction but don't have the funds on that particular chain. Take OpenSea as an example, because it is currently an NFT market only deployed on Ethereum, the complicated bridging operation and high gas cost exclude many users on other chains from participating in NFT transactions on OpenSea.
Celer IM can help expand the NFT marketplace to reach a wider audience. Auctions will be able to take place across chains other than the chain where the NFT was initially minted. Most importantly, there is no need for any separate cross-chain fund transfers to take place until the auction results are finalized. This significantly reduces the cost of participating in NFT auctions, lowers the barriers to complex operations, and expands the trading pool of the entire market.
So, how to achieve What do developers need to build these native cross-chain dApps?
In this module, we will gradually dismantle common application design patterns and introduce Celer The architecture of IM.
For many native cross-chain applications, the core process usually involves sending funds to one or more chains, and using those cross-chain funds to "do other tasks" on the target chain. The DEX demo given above actually uses this design pattern. In the following introduction, we will also provide specific code links for DEX demos.

Although the flow chart above looks complicated, most of the The process is completed by Celer IM, dApp developers only need to build IM Schema Application Template.
In Celer IM, the user no longer directly interacts with the existing smart contract of the dApp, but interacts with a new dApp Plug-in contract (marked A), expressing The cross-chain logic they want to execute. This dApp Plug-in becomes part of the entire dApp business logic and can interact with the existing smart contracts of the dApp on the source chain. Interactions with dApp Plug-in contracts are usually the only transactions issued by users to interact with this cross-chain dApp.
In the DEX example shown, transferWithSwap function is the starting point of the whole process, which allows users Express cross-chain logical requests, such as "first exchange Token A for Token B on the X chain, and then exchange the changed Token B for Token C on the Y chain".
Of course, usually users will not manually specify these requests, dApps using the Celer IM framework More abstract user targets should be constructed for calling such functions.
After completing the necessary operations on the source chain, the dApp Plug-in will send the converted funds and related messages to the target chain (marked B and C ). The message explains what needs to be done on the target chain. In this DEX In the example, the message is "Swap the cross-chain Token B with Token C, and then send Token C to the user". Just call sendMessageWithTransfer, message and funds transfer will automatically link together. The message is then sent to the Message Bus contract, and funds are transferred through an asset cross-chain bridge (such as cBridge).
Note: In this application mode, Celer IM is compatible with other asset bridges, taking cBridge as an example Because cBridge is the first asset bridge supported by IM.
To help you understand this step, we first introduce a core component in Celer IM: State Guardian Network (SGN ). SGN itself is a proof-of-stake (PoS) blockchain built on Tendermint, and under the IM architecture, it is a message router between different blockchains. Node providers must pledge CELR to become validators and join the consensus process of SGN. SGN uses the same security mechanism as L1 blockchains like Cosmos and Polygon PoS chains. SGN's CELR staking and slashing mechanisms are implemented on the Ethereum L1 smart contract.
SGN pledge nodes will continuously monitor the transactions that occur on all connected chains. When a transaction in the Message Bus contract triggers a message containing a scheduled header-payload format cross-chain message event (mark D), the verification node will first reach a consensus on "whether the message exists", and at the same time generate a weighted multi-signature bright. Then, this proof is stored on the SGN chain, waiting for the Executor subscribing to the message to relay to the target chain (marked H).
For asset cross-chain, we can regard the cBridge contract as a built-in asset cross-chain Chain-optimized Message Bus. SGN will carry out a consensus and proof process (mark E) similar to message cross-chain. However, when assets cross-chain, the SGN verifier will not relay the built-in asset cross-chain proof to an Executor under the chain, but directly send the on-chain transaction to the cBridge contract (marked F) on the target chain, and trigger Fund transfer, sent to the dApp Plug-in contract (marked G) on the target chain. Once again, I want to emphasize to everyone that Celer IM can be connected to any asset cross-chain bridge, but first of all, Celer's cBridge is supported by default.
The task of the Executor is to read the weighted multi-signature proof from the SGN blockchain and simply relay it to the Message Bus (marker I) on the target chain. Anyone can run an Executor for any application, since its function is only to relay messages. Of course, dApps should consider giving Executor incentives, because Executors are responsible for sending transactions and paying gas fees on the target chain.
The function of the Message Bus on the target chain is to check the proof message Validity, and confirm that the dApp Plug-in has indeed received the relevant payment (Mark J). Afterwards, the Message Bus will pass the message (logic execution instruction) to the dApp Plug-in contract (marked K) that hosts the cross-chain business logic of the dApp on the target chain.
The dApp Plug-in on the target chain only needs to implement executeMessageWithTransfer interface. In our DEX example, this function will execute the logic of "replace Token B with Token C" on the target chain.
< /p>
Of course, sending cross-chain messages or logical execution instructions does not necessarily accompany fund transfers. For example, in the NFT market, if users participate in auctions on other chains, they do not need to actually transfer funds to the target chain, but only need to lock funds in the source chain, and then they can bid to participate in the auction. Only after winning the auction, users need to transfer funds across chains.

This flow is just a simplified version of the first pattern. dApp Plug-in only needs to implement logic calls on the source chain sendMessage, and then implement it in the dApp Plug-in contract on the target chain executeMessage.
Due to the asynchronous nature of the above-mentioned cross-chain message mode, the application logic should include fault handling considerations. In these application modes, failures may occur in the following three steps and should be dealt with accordingly:
1. The source chain dApp logic execution failed. This has nothing to do with Celer IM and should be handled by the dApp business logic itself. Fault example: DEX Token exchange exceeds the time limit.
2. Cross-chain bridge asset cross-chain failure. The source chain dApp will be notified through a common interface and should handle the returned asset by retrying the asset cross-chain or sending the asset back to the user.
3. The target chain dApp logic execution failed. When user funds reach the target chain, the execution of dApp logic on the target chain may still fail. dApp developers should be prepared to implement some fallback functions for such failures. Common ways to deal with such failures are: stop executing logic and send funds to users on the target chain; or transfer funds back to the source chain. But the logic of how to implement the fallback function is entirely up to the dApp developer.
This article aims to abstract the design and dismantling of the IM architecture, we will not detail Introduce the process of troubleshooting, but provide detailed design patterns in development documentation refer to.
From the above two In the model, it can be clearly seen that if Celer IM is to run smoothly, CELR stakers and verifiers in SGN are essential.
SGN plays a role in reaching source chain message consensus and storing source chain messages in the IM architecture Prove and realize the role of cross-chain funds. In order for SGN to continue to provide services, users using Celer IM also need to pay fees to SGN similar to the fee model of any other PoS blockchain validator. The fee itself is distributed to CELR stakers according to the SGN node that produced the block.
In the Celer IM architecture, whether it is to expand the market size of the existing dApp or build a brand new dApp, it is very simple to implement, and only need to follow the following 3 steps:
First, you need to write the dApp Plug-in smart contract code. The logic implemented in the smart contract interface of the source chain only needs to be able to express the purpose of cross-chain execution, and can call sendMessage or sendMessageWithTransfer on the source chain; and also need to implement executeMessage or executeMessageWithTransfer in the dApp Plug-in contract of the target chain function.
The second step is to run the Executor. This step requires no coding. Both dApp development or community members can run an Executor and subscribe to relevant message proofs generated on SGN.
The final step is to make UI/UX tweaks. Since the cross-chain logic that the application now has may involve multiple transactions, it is naturally very important for users to understand the different states of a cross-chain behavior. The specific display of the UI depends on the application itself of course, but Celer IM provides an easy-to-query gateway service that allows dApps to obtain messages and cross-chain status of funds, allowing dApp developers to build a complete life cycle of a cross-chain transaction.
We are looking for dApp partners to build the Celer IM ecosystem together. Celer will provide technical support for partners, and we are also setting up special financial support, and will provide more details later. If you are interested in joining the Celer IM ecosystem, please contact us.
Original link
Welcome to join the official BlockBeats community:
Telegram Subscription Group: https://t.me/theblockbeats
Telegram Discussion Group: https://t.me/BlockBeats_App
Official Twitter Account: https://twitter.com/BlockBeatsAsia