05 / 05Advanced
Transfer strategies
FT4 includes three registration strategies that require the user to transfer tokens before an account exists: transfer open, transfer fee, and transfer subscription. Each requires a token transfer to activate the account, but they differ in how, or whether, you earn revenue from it.
Transfer open strategy
With transfer open, the user sends a set amount of tokens to an account that doesn't exist yet, then claims that account to activate it. Think of the non-existent account as an empty account waiting for funds. After activation, the user can spend the tokens that were sent to it.
This option sits between fully free registration and the paid strategies: a token transfer is required, but no fee is charged.
Code example for transfer open strategy
Start from the template using the transfer open examples and their tests.
Add this registration configuration to your chromia.yml file:
lib.ft4.core.accounts.strategies.transfer: rules: - sender_blockchain: x"0000000000000000000000000000000000000000000000000000000000000000" sender: "*" recipient: "*" asset: - name: "MyTestAsset" min_amount: 100L timeout_days: 60 strategy: - "open"Transfer fee strategy
Transfer fee asks the user to buy a set amount of tokens once to unlock your dapp's features. It suits users who want a single, straightforward step.
To register, the user transfers a set amount of tokens to a non-existent account, which is an empty account that must be topped up. When the tokens arrive, the fee is subtracted from the transferred amount.
Code example for transfer fee strategy
Start from the template using the transfer fee examples and their tests.
Add this configuration to your chromia.yml file:
lib.ft4.core.accounts.strategies.transfer: rules: - sender_blockchain: x"0000000000000000000000000000000000000000000000000000000000000000" sender: "*" recipient: "*" asset: - name: "MyTestAsset" min_amount: 100L timeout_days: 60 strategy: - "fee"lib.ft4.core.accounts.strategies.transfer.fee: asset: - name: "MyTestAsset" # issued by current blockchain amount: 40L fee_account: x"YOUR_FEE_ACCOUNT_ADDRESS" # All fees will be collected into this accountTransfer subscription strategy
Transfer subscription charges users on a recurring basis to keep using your dapp, giving you a steady income to maintain and develop it.
Setup involves a few steps. You first enable subscriptions in chromia.yml. The user then calls the transfer function, pays a predefined fee, and sends a set amount of tokens to a non-existent account, an empty account that must be funded and is central to the flow.
Next, the user calls the claim function to take ownership of that account. You control the subscription length with subscription_period_days in chromia.yml. Once the period expires, the account becomes inactive and can't be used. The user reactivates it by renewing, which means sending a set amount of tokens to the account.
Code example for transfer subscription strategy
Start from the template using the transfer subscription examples and their tests, which show the full implementation.
To enable subscriptions, paste this configuration into your chromia.yml file:
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_operationStrategy comparison
| Aspect | transfer open | transfer fee | transfer subscription |
|---|---|---|---|
| Fee required | No (a token transfer is still required) | Yes (one-time) | Yes (recurring) |
| Production use | Safe if safeguards are in place | Recommended | Recommended |
| Revenue model | No direct revenue | One-time payments | Recurring payments |
| User experience | Token transfer required | Single, simple payment | Payments needed regularly |
| Complexity | Low | Medium | High |
Configuration properties
| Property | Description |
|---|---|
sender_blockchain | The blockchain tokens are accepted from. In the example it is the chain with BRID x"0000000000000000000000000000000000000000000000000000000000000000". Set it to "*" to accept tokens from every chain in the Chromia network. |
sender | Who may send tokens to the dapp. "*" lets anyone send. |
recipient | Who may receive tokens in the dapp. "*" lets anyone receive. |
name | Name of the asset used for account registration. |
min_amount | Smallest transfer to a non-existent account that counts toward registration. |
timeout_days | Number of days a user has to claim a non-existent account that holds a balance. |
strategy | Which strategy type the registration process uses. |