DEV Community

Cover image for Composability in Flow: Unlocking Technical and Business Opportunities
Rami James
Rami James

Posted on

Composability in Flow: Unlocking Technical and Business Opportunities

Composability in blockchains refers to a framework that permits the interaction and interconnection of discrete elements, especially smart contracts. This kind of modular ecosystem is important as it helps programmers utilize existing components to build advanced systems very quickly.

In this article, we’ll look at composability — what it means, how it works on blockchain, some of its benefits and opportunities, and how it powers some of the innovations behind the Flow blockchain.

What is composability?

Composability is an age-old programming concept that saves developers (who are working within an ecosystem) from writing redundant code. This is achieved by abstracting out programming logic into logically independent units called functions.

For example, let’s say you’re building an application that needs to provide functionality to convert USD to INR on several pages. You could either write the same logic repeatedly on different pages or define it in a function and just call that function everywhere. In essence, this concept resembles constructing a monument using LEGO bricks, where the bricks are the composable functions.

Composability is like the compound interest of programming. Once someone solves a problem and publishes it in a modular way for others to use, the problem is solved for everyone.
Benefits of composability

Benefits of composability

Composability has several benefits.

  1. Saves developer hours: If developers use pre-existing functions written by other devs, it saves them a lot of time compared to if they implemented their own logic. This could be anywhere from three lines of code to 1,000 lines.

  2. Reduces probability of errors: This happens for two reasons. If every developer implemented logic on their own, there would be an increased risk of one of them making an error. Secondly, as the same logic gets used in multiple places, it creates several testers who are incentivized to make sure the logic works.

  3. Readability: Replacing hundreds of lines of code with a logical function name definitely enhances the readability of code for future developers.

  4. Easier to make changes: If a certain flaw is found or an update in logic is necessary, it can be done in one place instead of making the change in several places.

Composability in Blockchains

In blockchain, composability denotes the smooth intercommunication among distinct constituents, like smart contracts and dApps, within a network. Any smart contracts you write on the blockchain can use functionalities from other smart contracts and dApps.

One way blockchains like Ethereum have achieved this is via the creation of infrastructure-level composable units in the form of Ethereum Request for Comment (ERC), which are essentially proposals. These proposals, when approved by the Ethereum community, turn into smart contracts deployed and publicly available on-chain.

For example, ERC-721 is a smart contract standard for creating NFTs. It’s one of the most used composable units among NFT projects in the Ethereum ecosystem. These NFT projects just import and extend functions from ERC-721 to give their contracts powerful functionality right away.

Flash loans in decentralized finance (DeFi) are also a good example of composability among several platforms. To begin, you first create a set of predesignated operations on providers like Aave. Then you run transactions on different swap protocols, like MakerDAO and Uniswap. Eventually, you repay the flash loan and mint your profit.

Composability in Flow blockchain

Flow is a permissionless layer-1 blockchain that was built to support the high-scale use cases of games, virtual worlds, and the digital assets that power them. It excels in high-throughput settings such as decentralized gaming and NFT markets — situations that have a large transaction volume and high user engagement.

The Flow blockchain was built with composability in mind every step of the way. Let’s look at how.

Sharding versus multi-node architecture

There are two mechanisms commonly used in blockchains to achieve scalability: sharding for layer-1 solutions and rollups for layer-2 solutions. Ethereum, for example, has been transitioning recently from its single-node architecture to sharding. However, this has its own limitations.

In sharding, the state of the blockchain is split up into multiple smaller chunks and distributed across nodes. This makes it much harder to achieve composability, as a component that a smart contract might be referring to may be in a completely different shard chain.

Flow solves this problem in an innovative way, while also achieving scalability, through a process called pipe-lining.

In Flow, four types of nodes work together to make a transaction happen. Collection nodes collect well-formed transactions in the transaction pool to pass on to the consensus node. Consensus nodes then form and propose blocks to the blockchain. Then execution nodes actually execute the computations of a block and finally the verification nodes verify the accuracy of computations performed by the execution node.

You can read more about each of these nodes here. Below is an image that shows the sequential steps.

Image description

The benefit is that Flow is able to maintain a single shared state for the entire chain as it achieves scalability without breaking the state into shards. This is very powerful and ultimately maintains composability in Flow.

Composable resources in Cadence

In Cadence, the language used to write smart contracts on Flow, resources can be created, deployed, and moved by other resources. This is most commonly used in NFTs, where an NFT collection is defined as a resource. It then owns NFTs inside it, which are also resources. These NFTs defined inside the collection can be accessed and used by other contracts; only the access control is defined by the parent resource.

The contracts can also be written in a way that is generic and can be easily extended by other contracts.

Compatibility with EVM and Ethereum

The Flow blockchain ecosystem has recently announced compatibility with EVM. The benefits of this are twofold:

  • Popular Ethereum applications like Aave, MetaMask, Uniswap, and so on will be fully available out of the box on the Flow blockchain and do not need any porting. This will encourage developers to onboard the Flow blockchain.
  • Developers can enhance their existing Solidity smart contracts using Cadence on Flow. This encourages a new level of composability across chains.

You can read more about the announcement here. This was launched recently.

Business opportunities enabled by composability on Flow

Gaming and NFTs

Games might have several assets, like player accessories and skins, which are highly desirable among gamers. More often than not, these assets are obtained by the gamer after spending a lot of time on the game. If these assets are modeled as NFTs, the concepts of composability on Flow can be utilized to make them available across games.

This would mean:

  • Increased gamer engagement: Gamers will now know their assets are valuable even if their game shuts down. This will result in better financial outcomes for all.
  • Lower onboarding barrier: Every time a player starts a new game, they will not be starting from scratch as they already have some assets. This makes it very easy for games to acquire new players.
  • Increased “GDP”: Composability and interoperability will create a secondary market for assets that increases the overall GDP of the gaming ecosystem.

Publishing

Content, like written posts, can be modeled as NFTs and used across platforms. Recently, a partnership was forged between Zora, an NFT marketplace, and Mirror, a decentralized blogging platform. This partnership allowed writers on Mirror to package their popular articles as NFTs and auction them on Zora. This resulted in increased income for these writers. Similar models are possible on the Flow blockchain.

Writers can then use these funds to fuel their future projects.

DeFi

As previously mentioned, flash loans are constructed on the fundamentals of composability and prove very beneficial in market-making. Even normal tokens on Flow can be used across protocols and smart contracts owing to the tenets of composability.

Every token carries its own identity and code that defines its behavior. So every time a token exchanges hands, all the “composable” functions come with it.

Cross-chain projects

As mentioned earlier, it is now very easy for Ethereum projects to launch themselves on Flow and vice versa. This requires no new programming and can be done in a very short turnaround time.

This means popular projects on Ethereum can now tap the Flow ecosystem and its users. This also means that existing Flow projects will gain traction from existing Ethereum protocol users, who will now discover Flow.

This is a big win-win for both ecosystems and will boost traction overall in the world of blockchain.

Conclusion

The Flow blockchain has powerful built-in support for composability. This empowers Flow developers to build on top of existing infrastructure without having to write it on their own again. This also has a lot of added business advantages, as composability reduces time to market and increases interoperability. It will be interesting to see how compatibility between Flow and Ethereum evolves.

You can refer to the official docs page on multi-node architecture and composability to learn more. I also recommend that you get your hands dirty by going through Flow Docs.

Top comments (0)