Skip to main content

Set up a project

In this section, you set up a project to use FT3.

First, you clone FT3's bootstrap project repository:

git clone https://bitbucket.org/chromawallet/develop-chromia.git

Create a new directory for your project, and copy the postchain and Rell directories to your project. The remaining client contains an example for Single Sign-On (SSO) feature so that you can return to it later.

Set up blockchain

Config dapp description

  1. Go to postchain/config/nodes/, and you'll see a dev directory. This is the postchain config directory.
  2. Inside the dev directory, copy the file blochains/app/config.template.xml, and put the copy inside the Rell directory.
  3. Change the settings in the config.yml for your chain:
blockchains:
"YOUR_CHAIN_NAME": #Name of the blockchain
module: main #Entrypoint to the project
moduleArgs:
lib.ft3.core:
my_blockchain_name: "YOUR_DAPP_NAME"
my_blockchain_website: "YOUR_DAPP_WEBSITE"
my_blockchain_description: "YOUR_DAPP_DESCRIPTION"
rate_limit_active: 1
rate_limit_max_points: 10
rate_limit_recovery_time: 30000
rate_limit_points_at_account_creation: 1

compile:
rellVersion: 0.11.0

my_blockchain_name

Name of your chain.

my_blockchain_website

"Main page" URL of your dapp.

my_blockchain_description

Description of your dapp.

The following arguments are settings for the rate limiter (spam prevention). The client accumulates one "operation point" every rate_limit_recovery_time milliseconds, up to rate_limit_max_points. You spend one operation point for each operation.

rate_limit_active

0 for not active (no spam prevention) or 1 to activate the rate limit. Note that even if the rate limiter isn't active, you must set some values in the following args.

rate_limit_max_points

The maximum amount of operation points that are possible to accumulate (and therefore the maximum number of transactions that you can do at once).

rate_limit_recovery_time

(In milliseconds) period of cooling down before an account can receive one operation point.

rate_limit_points_at_account_creation

The points that an account has at the moment of its creation (0 is min).

note

Please note that if you use Single Sign-On, an account need to perform one operation immediately at the moment of creation to add disposable auth_descriptor (e.g., SSO needs rate_limit_points_at_account_creation at a minimum of one). Refer to the SSO Section for more information.

Set up database

Follow the instructions in Set up PostgreSQL database. Update the postchain/config/nodes/dev/node-config.properties file to match your database settings.

Run the chain

From the root of the blockchain, start your chain:

chr start -s config.yml

You can see the generated blockchain ID of the blockchain in the terminal that looks like this:

INFO  2120-01-01 23:59:59.999 [main] BaseConfigurationDataStore - Creating initial configuration for chain 1 with BC RID:
B61EFF348B43D7C93F67F6D2ABE17391D709A77F9A040D6309984665082DFE8A

Note down the blockchain ID; you need to use it to connect to the chain.

info

Postchain generates a blockchain ID for dapp based on its codebase. Whenever you change the blockchain code of the dapp, you need to wipe the database by adding the -wipe option to get a new blockchainID:

chr start --wipe

If you missed the log-in console, you could always see the previous log in the logs/logfile.log file.

Verify the chain is working

Go to the Chain Explorer, click the dropdown next to Vault, then choose add custom chain:

In the following popup, enter your chain's information using the information you entered in config.template.xml and the chain BRID:

If you see the chain's information displayed, then your chain is working properly:

If chain explorer can't connect to your chain, it indicates something is wrong with your settings from previous steps. Verify that the host and ports and your blockchainID are correct (7743 is the default port from node-config.properties).

With that, the blockchain side is ready. We can go on to the client side.


Set up client

The client directory you use in the Bootstrap project is an example client which works with the current chain. This section discusses how to create a client that connects to the chain.

Create a client directory for your project, run npm init (or bootstrap a project using a generator, create-react-app).

Add dependencies to the NodeJS project:

npm i --save ft3-lib
npm i --save postchain-client

Add other libraries to your liking.

Set config variables

Choose your method to set these important config variables:

export const blockchainRID = "<YOUR CHAIN BRID>";
export const blockchainUrl = "http://localhost:7743/"; // This is default value in node-config.properties file
export const vaultUrl = "https://dev.vault.chromia-development.com"; // Vault's url for SSO

That concluded the project setup process. In the next section, we can continue working with the client library and discuss the features of the ft3-lib npm package.