Flow Community Rewards is a game-changer, distributing value to people for their everyday use of Flow apps. The system incentivizes participation and enhances engagement within the Flow ecosystem, but what is the key to its functionality?
The answer lies in Cadence, a powerful resource-oriented programming language years in the making. Its latest version offers developers enhanced flexibility, control, and security.
Cadence Puts It All Onchain
Although many Web3 models attempt to mimic traditional finance structures with ledger-based ownership — otherwise known as identity-based security — technical limitations often emerge when it comes to committing data, logic, or rich media assets such as 3D images, jpegs, or movies onchain. For smart contract developers, thus far, the equivalence of onchain identity and user addresses have been the sole paradigm.
However, Cadence, the native smart contract programming language on Flow, unlocks an entirely new security paradigm. This model is known as capability-based access and it’s best summarized by Dieter Shirley (from the ERC721 standard) who said, “it’s not who you are but what you have”. In other words, Cadence unlocks true ownership — if you can access it, you own it.
Many of the other benefits in Cadence-based contracts are derived from the architectural and protocol-native features developers can take for granted on Flow. These include protocol-native account abstraction, proposer-builder separation, secure onchain randomness, and high degrees of unilayer state data availability and throughput.
With this rich featureset, Flow Community Rewards comprises a complex system of modular, object-oriented contracts that effectively amounts to a new and unique dynamic NFT collection. onchain logic to determine everything from the appearance of an NFT to fine-tuning reward and distribution models defining each stage of the lock & claim process.
You can take a look at one of these NFTs yourself with the script below:
import NonFungibleToken from 0x1d7e57aa55817448
import MetadataViews from 0x1d7e57aa55817448
import FlowRewards from 0xa45ead1cf1ca9eda
/// This script will resolve an owner's FlowRewards NFT Display
///
access(all)
fun main(): MetadataViews.Display? {
// Assign our parameters in question - these could be taken as args but are
// hardcoded here to demonstrate NFT display resolution
let ownerAddress: Address = 0xcea2dc27b31417ee
let nftID: UInt64 = 259484745147989
// Attempt to borrow a public reference to the owner's FlowRewards Collection
if let collection = getAccount(0xcea2dc27b31417ee).capabilities.borrow<&FlowRewards.Collection>(
FlowRewards.CollectionPublicPath
) {
// Attempt to borrow a view resolver for the given ID
if let resolver = collection.borrowViewResolver(id: nftID) {
// Resolve the view as a Display view
return resolver.resolveView(Type<MetadataViews.Display>()) as! MetadataViews.Display?
}
}
// If the Collection or NFT are not found, return nil
return nil
}
This code showcases how onchain logic can retrieve metadata tied directly to an NFT. The script retrieves a Rewards NFT display view from a given account’s collection by accessing the metadata tied directly to that NFT.
You can run the Cadence script above yourself at this link and the result you’ll see is as it exists exactly onchain, all without interacting with intermediary software. Take note of the long base 64 encoded data Uniform Resource Identifier (URI) — that’s the resulting svg image generated by the contract based on the NFT’s metadata and encoded on the fly.
Community Rewards is a great template of how Cadence makes dynamic onchain systems possible, in this case showcasing how the language creates non-fungible tokens (NFTs) that can own fungible assets. The onchain logic of Cadence allows for a malleable NFT in terms of appearance, ownership capabilities, and reward distribution that is fundamentally owned in every way —without offchain dependencies for owners to rely on to resolve the asset’s metadata or image.
The program hinges on a Rewards NFT that owns locked $FLOW. The instant $FLOW is locked in the rewards program, an NFT is minted — within that NFT is a vault that essentially contains and owns the locked $FLOW. Based on the amount of $FLOW locked, the contract logic programmatically determines the tier, total rewards, etc. related to that NFT, all of which are utilized to define the final SVG image rendered to requesters when they request the NFT’s metadata.
Anytime someone wants to re-up their locked token supply and recharge an NFT, or add more $FLOW to reach a higher tier in the program, they’re free to do so — when they do, the NFT’s physical appearance and metadata update because traits like its graphics and rewards are dynamically defined by the NFT’s onchain state.
Beyond Community Rewards, other Cadence assets are all highly configurable, with all elements residing onchain, including meta-data and supporting logic. Since Cadence’s ownership model is resource-oriented, these resources can literally own other resources. For Community Rewards, an NFT owns the locked $FLOW vault. And when that NFT is transferred, the locked $FLOW is transitively transferred as well — not because some contract says it's so but because the NFT and inner $FLOW is stored in the new owner’s account.
Cadence developers have the power to create whatever framework they desire, and commit the complex logic that supports those frames onchain to introduce changes that affect anything down to the metadata and physical appearance of an NFT, what it can own, and when it can own it.
The way Cadence and Flow address storage and ownership limitations unleashes developers, allowing them to calibrate any parameter of an asset they see fit with creative combinations of transparent onchain logic. Although it’s not strictly necessary to store NFT image data onchain, and many developers avoid doing so for efficiency, in this case, being able to do so with Cadence is a perfect fit for dynamic NFTs.
Cadence NFTs Go Deeper Than Metadata
The resource-oriented paradigm of Cadence allows for the creation of abstract models that leave room for evolution over time. In Flow Community Rewards, the program’s multi-tiered platform demonstrates this capacity, where stages and boosts can be defined or modified as necessary. Between preseason and Season 1 of Community Rewards, this function was used to top up reward boosts for locked $FLOW across the platform without disrupting system integrity or core functionality all without the need for contract updates.
Since the Rewards NFTs act as containers for locked $FLOW rather than a smart contract or another protocol, they avert centralization or code-related risks. After submitting $FLOW to the Cadence contract, the contract locks it into an NFT that is deposited into the submitter’s account — so locked $FLOW is in the account holding that NFT, not locked in a contract, or random pool.
Here the code demonstrates how Flow is locked within a Rewards NFT’s vault:
access(all) resource NFT : NFTPublic, NonFungibleToken.NFT {
/// The ID of the NFT
access(all) let id: UInt64
/// The sequence number of the NFT - used to determine the sequence of minting and to balance registered
/// summaries in contract storage
access(all) let sequence: UInt64
/// The FLOW locked within the NFT
access(self) let lockedVault: @FlowToken.Vault
/// ...
}
Although the contract disallows unlocking $FLOW from NFTs during the lock period, users still have access to liquidity by leveraging permissionless NFT marketplaces like Flowty to do as they see fit with their Rewards NFTs. Along with sovereign control of their locked resources, Cadence provides users with wider transferability with other Flow protocols that can easily identify the baseline value of a resource-based NFT as correlated with its bound assets.
Unlock The Future With Cadence
Cadence gives developers the tools to automate and solve distribution-related issues by enabling the seamless, onchain delivery of assets directly into NFTs in target user accounts. And while Community Rewards does well to demonstrate the vast power of Cadence, the rest is up to developers to unlock.
Learn more about how Cadence can empower applications for a more impactful, efficient, and value-driven onchain experience.