Chromia
Start Building

08 / 27Module 1: A Rell backend with FT accountsBeginner

FT4 accounts configuration

Here you install the FT4 library and set up accounts.

Install the FT4 library

Account management depends on the FT4 library, so add it first. Put the following configuration in your chromia.yml file:

chromia.yml
libs:  ft4:    registry: https://gitlab.com/chromaway/ft4-lib.git    path: rell/src/lib/ft4    tagOrBranch: v1.2.0r    rid: x"E96915FD7C9A5DD4E183D86F4A5B4BB5083A7CC1EDEB1465EDFFC926E67C93F6"    insecure: false  iccf:    registry: https://gitlab.com/chromaway/core/directory-chain    path: src/lib/iccf    tagOrBranch: 1.87.0    rid: x"9C359787B75927733034EA1CEE74EEC8829D2907E4FC94790B5E9ABE4396575D"    insecure: false

Configure FT4 accounts

Next, you add FT4 accounts to the app's model to strengthen how users authenticate.

Begin with the required module imports:

src/registration/module.rell
import lib.ft4.core.accounts.strategies.open. { ras_open };import lib.ft4.accounts.strategies. { register_account };

Then give the user entity an account field:

src/news_feed/model.rell
entity user {  mutable name;  key id: byte_array;  key account;}

With this, each user maps to exactly one FT4 account, and each account to exactly one user. Update the create_user operation so it creates an FT4 account as well:

src/registration/module.rell
operation register_user(name) {    val account = register_account();    val user = create user ( name, account.id, account );    create follower ( user = user, follower = user );}

The FT4 accounts and tokens documentation covers account permissions and the FT4 framework in depth.

In chromia.yml, move the test section so it sits under the blockchain tag, and add the admin public key:

chromia.yml
blockchains:  newschain:    module: main    moduleArgs:      lib.ft4.core.auth:        evm_signatures_authorized_operations:          - register_user      lib.ft4.core.admin:          admin_pubkey: "0359A8F2CE1BEF95F583169B7DF053AA227A93B2652B0A9C22975FEED638032610"    test:      modules:        - testcompile:  rellVersion: 0.14.9database:  schema: schema_newschain  libs:  ft4:    registry: https://gitlab.com/chromaway/ft4-lib.git    path: rell/src/lib/ft4    tagOrBranch: v1.2.0r    rid: x"E96915FD7C9A5DD4E183D86F4A5B4BB5083A7CC1EDEB1465EDFFC926E67C93F6"    insecure: false  iccf:    registry: https://gitlab.com/chromaway/core/directory-chain    path: src/lib/iccf    tagOrBranch: 1.87.0    rid: x"9C359787B75927733034EA1CEE74EEC8829D2907E4FC94790B5E9ABE4396575D"    insecure: false

To learn more about the options available in chromia.yml, see the Chromia project configuration documentation.

Written for this site from Chromia’s public course. Code samples are the course’s own.