Design Patterns: UTXO Transfers Using the Cell Model

By Jordan Mack
• Updated

This document explores different patterns for transferring digital assets between two parties using the Nervos CKB Cell Model. While focused on the CKB blockchain, these patterns may also apply to other UTXO blockchains that implement state rent.

State rent is essential because it ensures sustainable network economics and prevents out of control cost spirals. However, it introduces unique challenges that require innovative design patterns to maintain usability.

Some of the transfer patterns mentioned in this document are tied directly to specific asset protocols. This document aims to focus specifically on the transfer patterns introduced, not the details of the asset protocols themselves.

Challenges of State Rent

State rent presents unique obstacles for UTXO-based token transfers that don't exist in traditional blockchain models. Understanding these challenges is essential for designing effective transfer patterns.

CKB implements state rent through a simple economic model: 1 CKB token equals 1 byte of permanent on-chain storage capacity. When you create a cell containing smart contracts, assets such as tokens and NFTs, or any other data, the cell's capacity must cover the storage cost of all these components. This capacity remains locked the entire time the asset exists on-chain. When the assets are destroyed and the cell is consumed, the locked CKB is returned.

The amount of CKB that must be locked depends on the amount of required on-chain data, which can vary from asset to asset. For the most basic asset, the CKB native token, the cost is 61 CKB. For an SUDT token, the cost is 142 CKB. For assets such as NFTs, the cost varies but is usually in the 150-200 CKB range. For fully on-chain DOBs, the cost can easily exceed thousands of CKB.

The challenge is that when you send an asset to someone else, a cell must be created to hold it. This introduces additional costs to the sender if they pay the state rent for the receiver. However, there are multiple patterns to mitigate this depending on the situation.

Cell Model Asset Transfer Design Patterns

Several patterns can be used to address state rent costs for asset transfers. Each pattern balances simplicity, cost distribution, and trust requirements differently.

In the diagrams below, each box is a cell that holds assets and CKB capacity. A blue border marks a cell that is new or changed in that step. A yellow box is a cell with special rules, such as an ACP cell. Transaction fees are left out for simplicity.

Sender Pays State Rent Pattern

The sender covers all state rent costs for the receiver's new cell. The asset transfer creates a cell owned by the receiver with capacity paid entirely by the sender.

Sender Pays State Rent Pattern. The task is to send 50 CAT coin to the receiver. Initial State: The sender has a regular cell with 200 CAT coin and 500 CKB. The receiver has no cells. After Transfer: The sender has a regular cell with 150 CAT coin and 358 CKB. The sender keeps the rest. The receiver has a regular cell with 50 CAT coin and 142 CKB. The sender paid for this cell.

Pros:

  • Most simple and compatible method to implement.
  • No CKB requirements for receiver.
  • Single step process.

Cons:

  • Sender must pay extra CKB for the receiver's cell.
  • Scales poorly as CKB price increases.
  • Costs create high barriers for frequent transfers.

Send and Refund Pattern

The sender pays state rent initially, then the receiver refunds the CKB capacity back to the sender. This requires trust on the part of the sender, and the receiver must actively participate after receiving the asset.

Send and Refund Pattern. The task is to send 50 DOG coin to the receiver. Initial State: The sender has a regular cell with 200 DOG coin and 500 CKB. The receiver has a regular cell with 300 CKB. After Transfer: The sender has a regular cell with 150 DOG coin and 358 CKB. The sender keeps the rest. The receiver has a regular cell with 50 DOG coin and 142 CKB. The sender paid for this cell. The receiver has a regular cell with 300 CKB. The sender now trusts the receiver to pay back 142 CKB. After Refund (Receiver Chooses to Pay Back): The sender has a regular cell with 150 DOG coin and 358 CKB. The sender has a regular cell with 142 CKB. The receiver refunded 142 CKB. The receiver has a regular cell with 50 DOG coin and 142 CKB. The receiver has a regular cell with 158 CKB. The receiver keeps the rest.

Pros:

  • Sender does not pay the CKB for the receiver's cell.
  • Conceptually simple process that is easy to implement.

Cons:

  • Receiver must have CKB to pay the refund.
  • Receiver must be trusted to send back the CKB.
  • Requires automated bots for receiving applications.
  • No automated solutions exist for user to user transfers.

Anyone-Can-Pay (ACP) Pattern

The receiver creates a special cell which unlocks for any user when it detects that it is receiving additional assets, but remains securely locked in other scenarios. This is similar to a mail drop box, where anyone can make a deposit but it's not possible to take anything back out.

The receiver must create an ACP cell ahead of time to hold the specific asset they want to receive. This only needs to be done once per asset, and then it can receive indefinitely.

Anyone-Can-Pay (ACP) Pattern. The task is to send 50 PIG coin to the receiver. Initial State: The sender has a regular cell with 200 PIG coin and 500 CKB. The receiver has a regular cell with 300 CKB. After ACP Cell Creation (One Time): The sender has a regular cell with 200 PIG coin and 500 CKB. The receiver has an ACP cell with 142 CKB. Anyone can add PIG coin. Only the receiver can take it. The receiver has a regular cell with 158 CKB. The receiver keeps the rest. After Transfer: The sender has a regular cell with 150 PIG coin and 500 CKB. The sender keeps all 500 CKB. The receiver has an ACP cell with 50 PIG coin and 142 CKB. The sender added the coins. The receiver did not sign. The receiver has a regular cell with 158 CKB.

Pros:

  • Sender does not pay the CKB for the receiver's cell (after refund).
  • Mature and tested pattern and implementation.
  • No trust requirements.

Cons:

  • Receiver must have CKB to create the ACP cell.
  • ACP cells must be pre-deployed by receivers for each asset.
  • Limited wallet and tooling support.
  • More complex smart contract logic.

Resources:

Cheque Cell Pattern

Implements a mechanism similar to a bank cheque where the sender creates a special cell that can be "cashed" by the receiver. The receiver must provide their own CKB capacity to claim the asset, and the CKB used for the cheque cell is returned to the sender. If the cheque remains unclaimed after 6 epochs, the sender can withdraw the assets and reclaim the capacity.

Cheque Cell Pattern. The task is to send 50 DUCK coin to the receiver. Initial State: The sender has a regular cell with 200 DUCK coin and 500 CKB. The receiver has a regular cell with 300 CKB. After Cheque Creation: The sender has a regular cell with 150 DUCK coin and 338 CKB. The sender keeps the rest. The receiver has a regular cell with 300 CKB. A new cheque cell holds 50 DUCK coin and 162 CKB. The receiver can claim it at any time. The sender can withdraw it only after 6 epochs (about 24 hours). Then one of two outcomes happens. Outcome A: Receiver Claims: The claim spends the cheque cell. The sender has a regular cell with 150 DUCK coin and 338 CKB. The sender has a regular cell with 162 CKB. The sender gets back 162 CKB. The receiver has a regular cell with 50 DUCK coin and 142 CKB. The receiver paid for this cell. The receiver has a regular cell with 158 CKB. The receiver keeps the rest. Outcome B: No Claim After 6 Epochs: The sender's withdrawal spends the cheque cell. The sender has a regular cell with 150 DUCK coin and 338 CKB. The sender has a regular cell with 50 DUCK coin and 162 CKB. The sender controls it again. The receiver has a regular cell with 300 CKB.

Pros:

  • Sender does not pay the CKB for the receiver's cell.
  • Does not require the receiver to pre-deploy asset receiver cells.
  • No trust requirements.

Cons:

  • Receiver must have CKB to claim assets to a cell they own.
  • Unclaimed assets require the sender to undergo another step to recover.
  • Very limited wallet and tooling support.
  • More complex smart contract logic.

Resources:

  • Cheque Lock RFC - Official RFC specification for cheque lock, including example transactions.
  • Cheque Lock Script - Official cheque script implementation and documentation.

CoTA (Compact Token Aggregator) Pattern

CoTA is an NFT protocol which uses Sparse Merkle Trees (SMT) to manage large amounts of data off-chain while maintaining security guarantees on-chain. CoTA can be thought of as a layer 1.5 protocol that operates internally using the account-model, storing both data and ownership information in a distributed cell structure on top of UTXOs.

Each user creates a single permanent CoTA cell that becomes part of the distributed asset registry. Inside of each CoTA cell is a single SMT root hash consisting of exactly 32 bytes that provide provable information about the assets contained within the cell. The amount of data remains the same in a CoTA cell regardless of how many NFTs or how much data is associated with the user. An unlimited amount of NFTs can be created and held without increasing state rent costs.

CoTA builds on its distributed cell structure to add an innovative transfer mechanism that eliminate the immediate onboarding costs for new users to receive assets. CoTA assets operate on layer 1.5, which uses internal ownership tracking that is separate from the cell model. When assets are transferred on CoTA, they are marked for recipients without leaving the sender's cell. This means that CoTA NFTs effectively bypass the state rent requirements, allowing NFTs to be minted for near-zero cost and can be sent to new users who hold no CKB. The caveat being that the receiver cannot transfer an NFT again until they complete the one-time CoTA cell registration process and complete the claim process which moves the NFT from the original sender's CoTA cell to their own CoTA cell.

The CoTA transfer process involves four distinct stages:

Stage Sender Receiver Transfer Capability Notes
Initial Owns NFT No NFT Transferable The NFT is in the sender's cell.
After Transfer No NFT Owns Unclaimed NFT Not Transferable Ownership is marked, and the NFT stays in the sender's cell.
After Registration No NFT Owns Unclaimed NFT Not Transferable The receiver creates a CoTA cell to claim with. This step is optional.
After Claim No NFT Owns Claimed NFT Transferable The NFT is now in the receiver's cell. This step is optional.

The registration process has a one-time fee of 150CKB, which is non-refundable since the cell that is created effectively becomes part of CoTA's distributed cell structure. Registration is required to claim an NFT that has been marked for transfer, but it is not a requirement. Recipients will see unclaimed NFTs in their wallets just like normal NFTs, but they must register and claim if they want to send the NFT to someone else.

The following diagram illustrates how these stages work in practice with specific CKB capacity movements:

CoTA (Compact Token Aggregator) Pattern. The task is to send 1 FISH NFT to the receiver. Initial State: The sender has a CoTA cell with 150 CKB. It holds 1 FISH NFT. The receiver has a regular cell with 150 CKB. Aggregator: The sender owns 1 FISH NFT and can transfer it. After Transfer (Ownership Marked): The sender has a CoTA cell with 150 CKB. It records 1 FISH NFT as sent. The record stays as proof. The receiver has a regular cell with 150 CKB. No CKB is needed to receive. Aggregator: The receiver owns 1 FISH NFT but cannot transfer it yet. After Registration (Required to Claim; Optional): The sender has a CoTA cell with 150 CKB. It records 1 FISH NFT as sent. The receiver has a CoTA cell with 150 CKB. It was a regular cell before. Aggregator: The receiver owns 1 FISH NFT but cannot transfer it yet. After Claim (Optional): The sender has a CoTA cell with 150 CKB. It records 1 FISH NFT as sent. The claim used this record. The receiver has a CoTA cell with 150 CKB. It holds 1 FISH NFT. Aggregator: The receiver owns 1 FISH NFT and can transfer it.

Pros:

  • Sender does not pay the CKB for the receiver's CoTA cell.
  • Does not require the receiver to pre-deploy asset receiver cells.
  • Zero state rent cost for unclaimed transfers; claiming is not strictly required.
  • No trust requirements.

Cons:

  • Receiver must have CKB to register a CoTA cell before claiming.
  • CoTA's layer 1.5 protocol has some incompatibilities with other protocols.
  • Requires an off-chain aggregator service for interpreting data.
  • Limited wallet and tooling support.
  • Transactions are more complex and must be generated using the CoTA SDK in conjunction with an aggregator.

Resources:

Public Relay Cells Pattern (ACP Enhancement; Experimental)

Public relay cells are an optional enhancement to the Anyone-Can-Pay pattern that address the concurrency limitations by introducing public storage cells that act as temporary holding areas for token transfers. This pattern solves the collision problem where multiple simultaneous transfers to the same ACP cell would fail due to the deterministic nature of transfers on CKB.

In addition to increasing throughput to a single address by allowing parallel deposits, relay cells can serve as temporary holding areas for new users who haven't yet deployed their own ACP cells. This allows new users to receive tokens without any upfront CKB requirement, dramatically lowering the barrier to entry into the ecosystem.

The relay cells are serviced by a decentralized network of fulfillment bots that monitor deposits and deliver tokens to their final destinations. These bots compete to process transfers, earning small fees for providing this collection and delivery service. This creates a permissionless marketplace where anyone can operate a fulfillment bot, ensuring system resilience without single points of failure while creating earning opportunities for operators providing fulfillment services.

Public Relay Cells Pattern. The task is to send 50 BIRD coin to the receiver. Initial State: The sender has a regular cell with 200 BIRD coin and 500 CKB. The receiver has an ACP cell with 142 CKB. It is empty. Anyone can deposit to any relay cell, and service bots deliver. Relay cell 1 has 142 CKB. Relay cell 2 has 142 CKB. Relay cell 3 has 142 CKB. After Deposit to Relay: The sender has a regular cell with 150 BIRD coin and 500 CKB. The sender keeps the rest. The receiver has an ACP cell with 142 CKB. Relay cell 1 has 50 BIRD coin and 142 CKB. It is marked for the receiver. Relay cell 2 has 142 CKB. Relay cell 3 has 142 CKB. After a Service Bot Delivers: The sender has a regular cell with 150 BIRD coin and 500 CKB. The receiver has an ACP cell with 50 BIRD coin and 142 CKB. A bot delivered the coins. Relay cell 1 has 142 CKB. It is empty again. Relay cell 2 has 142 CKB. Relay cell 3 has 142 CKB.

Pros:

  • Sender does not pay the CKB for the receiver's cell.
  • Does not require the receiver to pre-deploy asset receiver cells (ACP cells).
  • No trust requirements.

Cons:

  • Receiver must eventually have CKB to claim assets to a cell they own.
  • Unclaimed assets may be returned or forfeited.
  • Emerging incomplete standard with no implementation.

Challenges: As this standard is still a work in progress, several challenges remain to be addressed. One concern is the potential for relay cell clogging if tokens remain unclaimed for extended periods. Proposed solutions include implementing asset forfeiture mechanisms after certain timeframes, which would incentivize timely claiming while preventing permanent blockage of relay resources.

Resources:

Harbor Pattern (Fractal Standard; Experimental)

Harbor is a pattern within the Fractal token standard which is currently in early development stages. The Fractal standard takes inspiration from CoTA, using Sparse Merkle Trees (SMT) to manage asset data off-chain while maintaining security guarantees on-chain. However, Fractal utilizes the Cell Model for ownership designation instead of a layer 1.5 account model structure. Harbors have similarities to public relay cells in being publicly available areas for asset storage, but Harbors can be used both as temporary storage and permanent storage.

A Fractal cell contains a single SMT root hash consisting of exactly 32 bytes, similar to a CoTA cell. The amount of data always remains the same regardless of how many assets are associated with the user, allowing for an unlimited amount of assets to be held without increasing state rent costs. A Fractal cell uses normal locks and allows the owner to control all assets within the cell.

A Harbor cell is a special kind of Fractal cell, which is created by anyone for public use. Anyone can store a Fractal asset in any Harbor by paying a small "parking fee" to the operator. Multiple Harbors can be created by anyone to create a competitive marketplace that keeps fees reasonable while providing parallelism for concurrent transfers. Should an operator wish to close their Harbor to recoup the CKB being used for state rent, they are free to do so at any time. However, if there are any Fractal assets stored within the harbor they are trying to close, they must migrate them to another open harbor and pay the parking fee for each asset.

Harbor cells can serve as holding areas for new users who haven't yet acquired any CKB to create their own Fractal cell, allowing them to bypass the state rent requirements. Since Fractal cells can hold any number of assets, they never will experience a "clogging" scenario that could happen with a public relay cell. For this reason, a Fractal cell is suitable for permanent storage. However, some smart contracts may not be able to operate normally with assets in a Harbor, and may still require withdrawal to a normal Fractal cell.

Note: The Fractal standard and Harbor pattern are in very early development and specifications may change significantly.

The Harbor transfer process involves up to four distinct stages:

Stage Sender Receiver Transfer Capability Notes
Initial Owns Assets No Assets Transferable The assets are in the sender's cell or a Harbor cell.
After Transfer No Assets Owns Assets in Harbor Transferable Ownership is marked, and the assets move to a Harbor cell.
After Registration No Assets Owns Assets in Harbor Transferable The receiver creates a Fractal cell to claim with. This step is optional.
After Claim No Assets Owns Assets Transferable The assets move to the receiver's cell. This step is optional.

The registration process requires 150CKB to create a Fractal cell, which is refundable if the cell is later destroyed. Registration is required to claim assets that have been stored in a Harbor, but it is not strictly necessary for ownership. Recipients use Harbor-stored assets as if they were holding them directly and can transfer them to other users as needed.

The following diagram illustrates how these stages work in practice with specific CKB capacity movements:

Harbor Pattern (Fractal Standard). The task is to send 75 WOLF coin to the receiver. Initial State: The sender has a Fractal cell with 150 CKB. It holds 75 WOLF coin. The receiver has a regular cell with 150 CKB. A Harbor cell has 150 CKB. The Harbor operator owns this cell. It holds no assets yet. Anyone can park assets here for a small fee. Aggregator: The sender owns 75 WOLF coin and can transfer it. After Transfer to Harbor: The sender has a Fractal cell with 150 CKB. It holds 0 WOLF coin. The assets moved to the Harbor. The receiver has a regular cell with 150 CKB. No CKB is needed to receive. A Harbor cell has 150 CKB. The Harbor operator owns this cell. It holds 75 WOLF coin for the receiver. Aggregator: The receiver can transfer 75 WOLF coin in the Harbor. After Registration (Required to Claim; Optional): The sender has a Fractal cell with 150 CKB. It holds 0 WOLF coin. The receiver has a Fractal cell with 150 CKB. It holds 0 WOLF coin. It was a regular cell before. A Harbor cell has 150 CKB. The Harbor operator owns this cell. It holds 75 WOLF coin for the receiver. Aggregator: The receiver can transfer 75 WOLF coin in the Harbor. After Claim (Optional): The sender has a Fractal cell with 150 CKB. It holds 0 WOLF coin. The receiver has a Fractal cell with 150 CKB. It holds 75 WOLF coin. The coins came from the Harbor. A Harbor cell has 150 CKB. The Harbor operator owns this cell. It holds no assets. Aggregator: The receiver owns 75 WOLF coin and can transfer it.

Pros:

  • Sender does not pay the CKB for the receiver's cell.
  • Does not require the receiver to pre-deploy asset receiver cells.
  • No trust requirements.

Cons:

  • Receiver must eventually have CKB to claim assets to a cell they own.
  • Requires an off-chain aggregator service for interpreting data.
  • Transactions are more complex and must be generated using the Fractal SDK in conjunction with an aggregator.
  • Emerging incomplete standard with no implementation.

Closing

The Cell Model's state rent requirement creates unique challenges for asset transfers that have sparked innovative design patterns that offer different trade-offs between simplicity, cost, trust, and user experience.

This document explores seven distinct transfer patterns for addressing state rent challenges in UTXO-based asset transfers:

  1. Sender Pays State Rent - The most straightforward approach where senders cover all capacity costs for receivers' new cells. While simple to implement and requiring no CKB from receivers, it scales poorly as CKB prices increase and creates barriers for frequent transfers.

  2. Send and Refund - A trust-based pattern where senders initially pay state rent, then receivers refund the capacity. Conceptually simple but requires active receiver participation and trust, with limited automated solutions for user-to-user transfers.

  3. Anyone-Can-Pay (ACP) - A mature, trustless solution using special cells that unlock when receiving assets. Requires receivers to pre-deploy cells for each asset type and has concurrency limitations, but offers proven reliability for users.

  4. Cheque Cell - Implements a bank cheque-like mechanism where senders create claimable cells with automatic withdrawal after timeout. Provides trustless transfers without pre-deployment requirements but adds complexity for managing unclaimed assets.

  5. CoTA (Compact Token Aggregator) - An innovative layer 1.5 protocol using Sparse Merkle Trees for off-chain data management. Virtually eliminates state rent for unclaimed transfers and allows near zero-cost minting, but requires off-chain aggregator infrastructure and has protocol incompatibilities.

  6. Public Relay Cells (Experimental) - An ACP enhancement using intermediate public storage cells to address concurrency limitations. Enables parallel deposits and serves new users without upfront CKB requirements, but relies on decentralized fulfillment bots and remains in experimental stages.

  7. Harbor (Fractal Standard; Experimental) - An emerging pattern within the Fractal token standard that combines the use of Sparse Merkle Trees for off-chain data management with decentralized public cells for asset storage. Allows for near zero-cost minting and eliminates state rent for newly onboarded users. However, the standard is in very early development with no current implementation.

Which Pattern to Use?

For Simple Applications:

  • Use "Sender Pays State Rent" for low-volume transfers where simplicity matters most.
  • Consider "Send and Refund" for applications which inherently require trust and the pattern offers few drawbacks.

For Production Applications:

  • Choose "Anyone-Can-Pay" for mature applications where deposits are made to an application where pre-deploying ACP cells is possible.
  • Select "Cheque Cell" when receivers cannot pre-deploy cells but trustless transfers are essential.
  • Consider "CoTA" for NFT applications where low-cost NFTs and unclaimed transfers provide significant user experience benefits.

For Future Applications:

  • Evaluate "Public Relay Cells" as a solution to scale ACP's concurrency limitations.
  • Monitor "Harbor" development for future ultra-low-cost asset solutions.