Skip to main content

Configure FT4 accounts

In this section, we'll walk you through the installation of the FT4 library and account configuration.

Install the FT4 library

Before we dive into accounts, let's install the FT4 library, which will help us manage accounts. To do this, add the following code to your chromia.yml file:

chromia.yml
libs:
ft4:
registry: https://gitlab.com/chromaway/ft4-lib.git
path: rell/src/lib/ft4
tagOrBranch: v1.0.0r
rid: x"FA487D75E63B6B58381F8D71E0700E69BEDEAD3A57D1E6C1A9ABB149FAC9E65F"
insecure: false

Then, execute the following command to install the library:

chr install

You should now have a new folder called src/lib/ft4 in your project directory, containing the Rell code of the library.

Configure FT4 accounts

In our app, we'll add FT4 accounts to our model. This change will provide a more sophisticated authentication mechanism.

First, import the necessary modules:

src/main.rell
import lib.ft4.core.accounts.{ account, single_sig_auth_descriptor, create_account_with_auth };

Next, add an account to a user:

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

This enforces a one-to-one mapping between an ft account and a user. Now, let's modify the create_user operation to also create an ft account:

src/main.rell
operation create_user(name, pubkey) {
val account = create_account_with_auth(single_sig_auth_descriptor(pubkey, set(["A", "T", "MySession"])));
create user ( name, pubkey, account );
}

Here, we call create_account_with_auth within an unprotected operation. This will be changed to a more secure verification in Lesson 5. The single_sig_auth_descriptor function creates an authentication descriptor that takes a single public key and a set of flags. A flag can be any text value, we use "A", "T" and "MySession" as a flag in this example. A and T are required on a new account, as they give the user administation and trasnfer rights when using the ft-library. The resulting account_id is used to create the user entity.

For more detailed information on account permissions and the FT4 framework, please refer to the FT4 Accounts and Tokens documentation.

We must now add move the test section to be under the blockchain tag of our chromia.yml.

chromia.yml
blockchains:
news-feed:
module: main
test:
modules:
- test

For more details on configuring your chromia.yml file, you can refer to the Chromia Project Configuration documentation.