Skip to main content

Create an account with the transfer fee strategy

When using the transfer fee strategy, users must pay a predefined fee to register an account. You can specify the fee amount by modifying the value in the amount field under the lib.ft4.core.accounts.strategies.transfer.fee section of the configuration file, chromia.yml. For more information about the transfer fee strategy, refer to the corresponding topic in the Dapp Monetization course.

Here is the fixed fee strategy configuration that you can add to your chromia.yml file:

chromia.yml
blockchains:
transfer-fee:
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: "fee"
lib.ft4.core.accounts.strategies.transfer.fee:
asset:
- issuing_blockchain_rid: x"D24027F108928CFA2F419A564469772EB6CB83DCCD902E93212083642BBF7270"
name: "Test"
amount: 5000000L
fee_account: x"96f52eee8f3fb1eccdef68f10b5e71d1e68bc3e080c8ac06ea2e60819acf9b35"
main:
my_fee_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_fee

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: "fee"
lib.ft4.core.accounts.strategies.transfer.fee:
asset:
- issuing_blockchain_rid: x"0000000000000000000000000000000000000000000000000000000000000000"
name: "Test"
amount: 5000000L
fee_account: x"96f52eee8f3fb1eccdef68f10b5e71d1e68bc3e080c8ac06ea2e60819acf9b35"
lib.ft4.core.admin:
admin_pubkey: "020E362CD8F8A94F2DB470564E667BD906812BC4ABB1C075650E3787E711B779D7"
main:
my_fee_account: x"02305E75D7C10987F916A81BFA4B90067322EEE116EB47361BF943DD0761CAA99A"

The code example provided below serves the following purposes:

  • It registers a specific asset on the current chain to allow paying a fixed fee. Refer to the FT4 documentation for more details.
  • It registers an account for our dapp that will receive fees from accounts registered by users.

The dapp_meta object contains the code that facilitates both the registration of an asset and the creation of an account that will collect fees.

src/main.rell
module;

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

struct module_args {
my_fee_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_fee_account, set(["A", "T"])));
}

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