Skip to main content

Create an account with the transfer subscription strategy

When implementing the transfer subscription strategy, users can establish new accounts by paying a specific subscription fee. The recurring fee is divided into two parts from a technical perspective: the duration for which the subscription remains active until it expires and the subscription amount. These values can be adjusted using the subscription_period_days and amount properties in the chromia.yml configuration file. For more details, please refer to the relevant section in the Dapp Monetization course.

To enable the transfer subscription strategy, add the following details to the chromia.yml file:

chromia.yml
blockchains:
transfer-subscription:
module: main
moduleArgs:
lib.ft4.core.accounts.strategies.transfer:
rules:
- sender_blockchain: x"D24027F108928CFA2F419A564469772EB6CB83DCCD902E93212083642BBF7270"
sender: "X"
recipient: "X"
asset:
issuing_blockchain_rid: x"D24027F108928CFA2F419A564469772EB6CB83DCCD902E93212083642BBF7270"
name: "Test"
min_amount: 10000000L
timeout_days: 15
strategy: "subscription"
lib.ft4.core.accounts.strategies.transfer.subscription:
asset:
- issuing_blockchain_rid: x"D24027F108928CFA2F419A564469772EB6CB83DCCD902E93212083642BBF7270"
name: "Test"
amount: 5000000L
subscription_period_days: 30
subscription_account: x"96f52eee8f3fb1eccdef68f10b5e71d1e68bc3e080c8ac06ea2e60819acf9b35"
main:
my_subscription_account: x"02305E75D7C10987F916A81BFA4B90067322EEE116EB47361BF943DD0761CAA99A"

libs:
ft4:
registry: https://bitbucket.org/chromawallet/ft3-lib
path: rell/src/lib/ft4
tagOrBranch: v0.8.0r
rid: x"B6AE6AC82AC735BFB9E4E412FFB76BF95380E94F371F5F6A14E71A3AA7D5FEF6"
insecure: false

compile:
rellVersion: 0.13.5

database:
schema: schema_transfer_subscription

test:
modules:
- test
moduleArgs:
lib.ft4.core.accounts.strategies.transfer:
rules:
- sender_blockchain: x"0000000000000000000000000000000000000000000000000000000000000000"
sender: "*"
recipient: "*"
asset:
issuing_blockchain_rid: x"0000000000000000000000000000000000000000000000000000000000000000"
name: "Test"
min_amount: 10000000L
timeout_days: 15
strategy: "subscription"
lib.ft4.core.accounts.strategies.transfer.subscription:
asset:
- issuing_blockchain_rid: x"0000000000000000000000000000000000000000000000000000000000000000"
name: "Test"
amount: 5000000L
subscription_period_days: 30
subscription_account: x"96f52eee8f3fb1eccdef68f10b5e71d1e68bc3e080c8ac06ea2e60819acf9b35"
main:
my_subscription_account: x"02305E75D7C10987F916A81BFA4B90067322EEE116EB47361BF943DD0761CAA99A"
lib.ft4.core.admin:
admin_pubkey: "020E362CD8F8A94F2DB470564E667BD906812BC4ABB1C075650E3787E711B779D7"

The code example provided below serves the following purposes:

  • It registers a specific asset on the current chain to enable the payment of a subscription fee. For more details, please refer to the FT4 documentation.
  • It registers an account for our dapp that will receive subscription fees from accounts registered by users.

The code within the dapp_meta object facilitates the registration of an asset and the creation of an account to collect fees.

src/main.rell
module;

import lib.ft4.accounts.strategies.transfer.subscription;
import lib.ft4.assets.{ asset, Unsafe };
import lib.ft4.core.accounts.{ account, create_account_with_auth, single_sig_auth_descriptor };

struct module_args {
my_subscription_account: pubkey;
}

object dapp_meta {
asset = Unsafe.register_asset("Test", "TST", 6, chain_context.blockchain_rid, "https://url-to-asset-icon");
account = create_account_with_auth(single_sig_auth_descriptor(chain_context.args.my_subscription_account, set(["A", "T"])));
}

For a complete code example, refer to the Cookbook repository.