01 / 07Advanced
Event-driven multi-chain dapps with ICMF
This course walks you through building a decentralized application (dapp) made of three blockchains: Order, Factory, and Delivery. They communicate through Chromia's Inter-Chain Messaging Facility (ICMF).
What is ICMF?
ICMF is the part of the Chromia network that lets blockchains exchange messages or events with one another automatically. No user action is needed to pass a message along.
- Event-driven communication: A chain publishes events on a given topic. Any chain subscribed to that topic can respond when the event occurs.
- Separation of concerns: Every chain handles only its own job and reacts only to the events from other chains that matter to it.
- Scalable and flexible: To add a chain, you subscribe it to the topics it needs. The logic of the existing chains stays untouched.
ICMF suits multi-blockchain dapps whose components must coordinate, for example in supply chains, games, or modular business software.
You will build an ordering system split across three blockchains:
- Ordering chain: Where users place orders for products.
- Factory chain: Manufactures products and tracks how many have been produced.
- Delivery chain: Takes care of getting orders to customers.
The design gives each actor its own area of responsibility. The order chain lists products that users can order. Factory workers work only with the factory chain, and delivery companies work only with the delivery chain. Keeping these roles apart makes the system modular and easier to scale.
A dapp can be divided into multiple blockchains in other ways too. Sharding is one option: you could run several factories for different product types to spread the workload in parallel or to operate on different time scales. The design used here, though, is a good fit for learning ICMF.
Here is a model of the system:
Think of ICMF as a message queue. A chain emits events on a topic, and other chains subscribe to that topic. This mechanism is central to Chromia's architecture because it lets blockchains talk to each other without user interaction.
Example use cases
- Supply chain management: Ordering, manufacturing, and delivery each run on their own chain. Placing an order makes the order chain tell the factory chain to begin production. Once the product is ready, the factory chain tells the delivery chain.
- Gaming: Player actions, in-game assets, and tournaments can live on separate chains. An achievement recorded on one chain can send a message that triggers rewards or events on another.
- Decentralized finance (DeFi): Lending, trading, and collateral management can run as separate chains that share events such as a loan approval or a liquidation, causing follow-up actions elsewhere in the system.
- Modular business applications: HR, payroll, and project management can each have a dedicated chain and exchange messages to coordinate tasks such as onboarding an employee or launching a project.
- IoT and automation: Chains representing devices can emit events, for instance sensor readings or alerts, that cause control or analytics chains to act.
How does ICMF work?
In Rell, sending an ICMF message takes little code. Behind the scenes, the following steps occur:
- The sending dapp calls
send_messagefrom the ICMF Rell library. The call can come from a user or from the dapp itself. - That call emits an event on the node, and the event is forwarded to the cluster's anchoring chain.
- Before building each block, the receiving node polls for messages on the topics it subscribes to.
- If it finds a message, the node invokes the special operation
__icmf_messageon the dapp. - The ICMF library then calls
receive_icmf_message, which runs whatever logic the dapp has defined.
This pattern works well when you want a chain to announce that an action has finished and have other chains subscribe and respond. Adding a chain with a new role only requires subscribing it to the relevant topics; the sending chain needs no changes.
In this course, for example:
- Factory workers do not need to know who placed an order or when. They only need to know an order exists so they can begin manufacturing.
- The delivery company needs to know which products go where, not what each box contains.
Related materials
The following documentation covers the concepts and techniques this course builds on:
| Section | Type | Documentation |
|---|---|---|
| Overview | Cross-chain | ICCF |
| FT4 | Introduction | FT4 |
| Overview | Dapps | Building your dapps on Chromia |
Repository link
You can find the full source code for this course in the ICMF course repository.