The Power of Resource-Oriented Programming in Flow/Cadence: A Deep Dive

Michael Bogan
6 min readNov 13, 2023

Flow is a permissionless layer-1 blockchain built to support the high-scale use cases of games, virtual worlds, and the digital assets that power them. The blockchain was created by the team behind CryptoKitties, Dapper Labs, and NBA Top Shot.

One of the best features of Flow is that it supports the paradigm of resource-oriented programming. Resource-oriented programming is a new way of managing memory where resources are held “in-situ” by the resource owner instead of in a separate ledger. This is very relevant for managing scarce and unreplicable digital resources on the blockchain.

In this article, I’ll do a deep dive into resource-oriented programming — and allow you to better manage your resources in your Flow smart contracts.

Source

What is resource-oriented programming?

In resource-oriented programming, objects are labeled as “resources”. Resources are a collection of variables and functions that only have exactly one copy at a time. Resources provide better composability than EVM and WASM.

When something is called a resource, there are very specific rules for interacting with it. The three rules that apply to resources in resource-oriented programming are as follows:

  1. Each resource exists in only one memory location — Resources cannot be duplicated.
  2. Ownership of a resource is defined by where it is stored — No central ledger that keeps track of ownership
  3. Only the owner of the resource can access its methods.

To explain this better: In the real world, if you claim to own a watch, that ownership is proven by the fact that you possess it yourself. There is no central ledger that people refer to check if you are the owner. However, in programming, when we think of ownership, we think of a mapping somewhere in a ledger of the object ID to the owner ID. For example, in the case of ERC721 smart contracts, the ownership of digital assets is stored in a ledger owned by the main smart contract.

Flow changes this paradigm of ownership by storing “resources” in the memory location owned by the owner itself (see image below). This means that if you’re holding a…

--

--

Michael Bogan

25 years of startups, products, and software architecture. Currently run DevSpotlight — tech content for tech companies. michael@devspotlight.com.