Chromia
Start Building

03 / 06Intermediate

System overview

The dapp you are building runs on two blockchains: the Subscription Chain and the Digital Warehouse Chain.

To set up a subscription, the user makes a payment on the Subscription Chain, which deducts a set amount from their account. You can later customize and extend this payment flow with the FT library. The user then shows the payment receipt to the Digital Warehouse Chain to gain access. Once inside, the user can update the inventory of a fictional warehouse.

With this design, you can run several warehouses by deploying several warehouse chains. Because payment processing lives on a separate chain, this component could also become part of a larger, more flexible system.

Subscription model

You represent a subscription as a structure that is sent to the Subscription Chain and checked later on the Digital Warehouse Chain. When the warehouse verifies a payment, it reads this structure as metadata. Start by creating a directory named src/subscription_chain and adding a module.rell file inside it.

src/subscription_chain/module.rell
module;

Next, add an entities.rell file to the src/subscription_chain directory with this code:

src/subscription_chain/entities.rell
struct subscription {    account_id: pubkey;    period;}enum period {    WEEK,    MONTH,}val MILLIS_IN_A_DAY = 24 * 60 * 60 * 1000;

Then add a functions.rell file to src/subscription_chain with this code:

src/subscription_chain/functions.rell
function period_price(period): integer {    return when (period) {        MONTH -> 90;        else -> 30;    };}function period_to_millis(period): integer {    return MILLIS_IN_A_DAY * when (period) {        MONTH -> 30;        else -> 7;    } ;}

A new subscription request records the account ID and the period. Helper functions map that period to its price and its duration.

Written for this site from Chromia’s public course. Code samples are the course’s own.