Skip to main content

Subscription fee strategy

The subscription fee strategy allows a dapp to implement a recurring payment model.

Two ways to implement subscriptions:

  • Automatic activation: Users transfer a set amount of a specified token upon registering. If the transferred amount meets the minimum requirement, their account is created with the subscription active.
  • Self-serve activation: Users with existing tokens on another chain can transfer the subscription fee directly.

Benefits of subscriptions:

  • Recurring revenue: Provides a predictable income stream to support dapp sustainability.
  • Easy setup: Simple implementation offers clear advantages to users.

Getting started

A code example with tests is available here.

To begin, expand the app configuration as shown below.

blockchains:
<my_blockchain_name>:
module: <my_module_name>
moduleArgs:
lib.ft4.core.admin:
admin_pubkey: "030F1B600A04BE704499CA4EDCEDD767FC16035522AB40AEB700D391412CD721EA"
lib.ft4.core.accounts.strategies.transfer.subscription:
asset:
- name: "MyTestAsset" # issued by current blockchain
amount: 10L
subscription_period_days: 30
free_operations:
- some_free_operation
subscription_account: x"66A117242F7CF1B1E6B830232FD1CA059A6E5111CEE99C8FDC2AFF8CE11BDDE4"
lib.ft4.core.accounts.strategies.transfer:
rules:
- sender_blockchain: "*"
sender: "*"
recipient: "*"
asset:
- name: "MyTestAsset"
min_amount: 100L
timeout_days: 60
strategy:
- "subscription"
compile:
rellVersion: 0.13.14
database:
schema: schema_my_rell_dapp
test:
modules:
- test
moduleArgs:
lib.ft4.core.admin:
admin_pubkey: "030F1B600A04BE704499CA4EDCEDD767FC16035522AB40AEB700D391412CD721EA"
lib.ft4.core.accounts.strategies.transfer.subscription:
asset:
- name: "MyTestAsset" # issued by current blockchain
amount: 10L
subscription_period_days: 30
free_operations:
- some_free_operation
subscription_account: x"66A117242F7CF1B1E6B830232FD1CA059A6E5111CEE99C8FDC2AFF8CE11BDDE4"
lib.ft4.core.accounts.strategies.transfer:
rules:
- sender_blockchain: "*"
sender: "*"
recipient: "*"
asset:
- name: "MyTestAsset"
min_amount: 100L
timeout_days: 60
strategy:
- "subscription"
libs:
ft4:
registry: https://gitlab.com/chromaway/ft4-lib.git
path: rell/src/lib/ft4
tagOrBranch: v1.1.0r
rid: x"FEEB0633698E7650D29DCCFE2996AD57CDC70AA3BDF770365C3D442D9DFC2A5E"
insecure: false
iccf:
registry: https://gitlab.com/chromaway/core/directory-chain
path: src/iccf
tagOrBranch: 1.32.2
rid: x"1D567580C717B91D2F188A4D786DB1D41501086B155A68303661D25364314A4D"
insecure: false

This configuration includes two main settings, strategies.transfer and strategies.transfer.subscription. The example above specifies the following:

  1. Transfer strategy: For any sender and recipient on any blockchain, transactions involving the "MyTestAsset" asset with a minimum amount of 100 coins can request a subscription. The timeout period is set to 60 days.
  2. Subscription strategy: The subscription price is set at 10 "MyTestAsset" coins for a 30-day period. Users may perform some_free_operation even without an active subscription.

To test the configuration above, refer to the provided tests.