Skip to main content

Transfer subscription strategy

When implementing a transfer subscription strategy for your dapp, users will need to pay regularly to access its functionality. This approach helps generate a steady income to sustain and grow your dapp.

To set up the transfer subscription strategy, you'll need to go through several technical steps. First, configure the chromia.yml file to enable subscriptions. Then, users must call the transfer function, pay a predefined fee, and transfer a specific amount of tokens to a non-existent account. This non-existent account represents an empty account that needs to be filled with tokens and is a crucial part of the process.

Afterward, users must invoke the claim function to claim the non-existent account. You can set the desired subscription period by configuring the subscription_period_days in the chromia.yml file. When the subscription period ends, the account becomes inactive and cannot be used further. To reactivate the account, users must renew the subscription by sending a specific amount of tokens to the account.

Benefits of transfer 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. Transfer 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.