setnode

Note: Before setting up a node, make sure you have installed DMC locallyInstall Operating Enviroment

Start a local DMC node so that you can develop specific functionalities of DMC locally. In the actual development environment, you will need different plugins to run a DMC node.

Create a new folder named start_dmc and save the code in start_dmc/node.js

1
const dmc = require("chain");

Configure HTTP Service

http plugin

For example, http-server-address is used to configure the local service address, with the default value being 127.0.0.1:8888.

1
2
3
dmc.load('http', {
'http-server-address': '0.0.0.0:8888'
});

For specific HTTP configuration information http plugin

Configure Chain Information

chain plugin

For example, delete-all-blocks is used to determine whether to delete all state data and block data, with the default value being false.

1
2
3
dmc.load('chain',{
'delete-all-blocks':true
});

For specific Chain configuration information, please refer to the chain plugin

Get P2P Information

net plugin

p2p-listen-endpoint is used to listen to the address and port for P2P connections, with the default value being 0.0.0.0:9876.

1
2
3
dmc.load('net',{
'p2p-listen-endpoint':'0.0.0.0:9876'
})

For specific Net configuration information, please refer to the net plugin

Control Block Production Information

producer plugin

producer-name:Control Block Production Information

enable-stale-production:enables block production even if the blockchain is frozen.

1
2
3
4
dmc.load('producer', {
'producer-name': 'dmc',
'enable-stale-production': true
});

For specific Producer configuration information, please refer to the producer plugin

Modify and View DMC Configuration and Data Directories

dmc.data_dir:the directory where DMC data is stored.

dmc.config_dir:the directory where DMC configuration is stored.

1
2
dmc.config_dir = 'dmc_config_dir/';
dmc.data_dir = 'dmc_data_dir/';

Start the Node

1
dmc.start();

Advanced Configuration

1
2
3
4
5
6
7
dmc.load('http', {
'http-server-address': '0.0.0.0:8889'
});

dmc.load('net', {
'p2p-listen-endpoint': '0.0.0.0:9877'
});
1
2
3
4
5
6
7
// Modify DMC configuration and data directories
dmc.config_dir = 'dmc_config_dir/';
dmc.data_dir = 'dmc_data_dir/';

// View DMC configuration and data directories
console.notice('config_dir:', dmc.config_dir);
console.notice('data_dir:', dmc.data_dir);
1
2
3
dmc.load('chain', {
'delete-all-blocks': true
});

For more plugins click here

Node Code Instance

Save the following code in start_dmc/genesis.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
"initial_timestamp": "2023-03-17T00:00:00.000",
"initial_key": "DM6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"initial_configuration": {
"max_block_net_usage": 1048576,
"target_block_net_usage_pct": 1000,
"max_transaction_net_usage": 524288,
"base_per_transaction_net_usage": 12,
"net_usage_leeway": 500,
"context_free_discount_net_usage_num": 20,
"context_free_discount_net_usage_den": 100,
"max_block_cpu_usage": 200000,
"target_block_cpu_usage_pct": 1000,
"max_transaction_cpu_usage": 150000,
"min_transaction_cpu_usage": 100,
"max_transaction_lifetime": 3600,
"deferred_trx_expiration_window": 600,
"max_transaction_delay": 3888000,
"max_inline_action_size": 4096,
"max_inline_action_depth": 4,
"max_authority_depth": 6
}
}

Save the following code as start_dmc/node.js to start a local DMC node.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const dmc = require("chain");

dmc.config_dir = 'dmc_config_dir/';
dmc.data_dir = 'dmc_data_dir/';
dmc.name = "dmc"
dmc.load('http', {
'http-server-address': '0.0.0.0:8888'
});
dmc.load('chain', {
'delete-all-blocks': true,
"genesis-json": "genesis.json"
});
dmc.load('net', {
'p2p-listen-endpoint': '0.0.0.0:9876'
})
dmc.load('producer', {
'producer-name': 'dmc',
'enable-stale-production': true
});
dmc.load('chain_api');
dmc.start();

Note: If you encounter any issues during development and testing, try restarting the DMC node service!

Run DMC development environment:

1
$ dmc start_dmc/node.js

Log output (partial)

1
2
3
$ dmc start_dmc/node.js
……
info 2023-04-08T03:48:47.900 thread-0 producer_plugin.cpp:2443 produce_block ] Produced block 3b0b39149bd407db... #2 @ 2023-04-08T03:48:48.000 signed by dmc [trxs: 0, lib: 1, confirmed: 0]

If you see the above messages, it indicates that the operation was successful and dmc has started block production.

Next Chapter:
👉 【write ABI Files