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.
lib.ft4.core.accounts.strategies.transfer:
rules:
- sender_blockchain: x"0000000000000000000000000000000000000000000000000000000000000000"
sender: "*"
recipient: "*"
asset:
- name: "MyTestAsset"
min_amount: 100L
timeout_days: 60
strategy:
- "subscription"
lib.ft4.core.accounts.strategies.transfer.subscription:
asset:
- name: "MyTestAsset" # issued by current blockchain # OR id: x"C633343E4AA3213EA92158648F11BA8DFF606C6CAC80614CFA5F45E57367F823"
amount: 10L
subscription_period_days: 30
free_operations:
- some_free_operation
This configuration includes two main settings, strategies.transfer
and strategies.transfer.subscription
. The example
above specifies the following:
- 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.
- 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.