account

What is an Account?

Generating Public and Private Keys

Tips: The generated public and private key pairs need to be kept secure and must not be shared with anyone! When asking someone to help register a DMC account, you only need to provide your public key. Anyone who claims to help register a DMC account and asks for your private key is a fraud!

Generating with dmc.js’s ECC

1
2
3
4
5
6
7
8
var DMC = require('dmc.js');
var prikey = DMC.ecc.randomKey_sync(undefined, { secureEnv: true });
var pubkey = DMC.ecc.privateToPublic(prikey);
console.log('public key: %s\n private key: %s',pubkey,prikey);

// output:
// public key: DM6smdPjLVZ9rdWfSvHND3xUgAdFq1o9b4yNyRi4KJAid74o7HGR
// private key: 5J2k1YSbjrG4cPEC8QSbqjr4kBbo2JgTjVw4aEqVBBkmWrrD5q1

Creating an Account

Creating a New Account

Call the newaccount method with the following parameter explanations:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var DMC = require('dmc.js');
var dmc_client = DMC({
chainId: 'c102a8115bef9e4a4e751559aac2cdc2859417e6476f8cb6054cd3f7dffe1ce4',
keyProvider: 'creator_priKey',
httpEndpoint: 'http://testnode.dmctech.io:8801',
logger: {
log: null,
error: null
}
});

dmc_client.transact_sync({
actions: [
{
account: 'dmc',
name: 'newaccount',
authorization: [{
actor: "Creator Name", //The name of the account that will create the new account is called the "Creator Name".
permission: 'active',
}],
data: {
creator: "Creator Name", //The name of the account that will create the new account is called the "Creator Name".
name: "Account Name", //The name of the account being created is called the "Account Name".
owner: {
threshold: 1,
keys: [{
key: "Owner Key", // The permission public key for the account being created.
weight: 1
}],
accounts: [],
waits: []
},
active: {
threshold: 1,
keys: [{
key: "Active Key", //The permission public key for the account being created.
weight: 1
}],
accounts: [],
waits: []
},
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});

Buy RAM

Storing account information on the blockchain requires the consumption of RAM. The creator needs to buy RAM for the account being created in order to store the new account’s information.

The buyrambytes method is called with the following parameter names explained:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var DMC = require('dmc.js');
var dmc_client = DMC({
chainId: 'c102a8115bef9e4a4e751559aac2cdc2859417e6476f8cb6054cd3f7dffe1ce4',
keyProvider: 'creator_priKey',
httpEndpoint: 'http://testnode.dmctech.io:8801',
logger: {
log: null,
error: null
}
});

dmc_client.transact_sync({
actions: [{
account: 'dmc',
name: 'buyrambytes',
authorization: [{
actor: 'from', // The name of the account that will create the new account.
permission: 'active',
}],
data: {
payer: 'from', // The name of the account that will create the new account.
receiver: 'Receiver Account',//The name of the account being created is called the “Receiver Account”
bytes: 'bytes' // Size of RAM to be purchased.
},
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
})

Stake Resources

The creator delegates DMC to the new account to obtain CPU and NET resources, enabling the new account to perform transactions.

The delegatebw method is called with the following parameter names explained:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var DMC = require('dmc.js');
var dmc_client = DMC({
chainId: 'c102a8115bef9e4a4e751559aac2cdc2859417e6476f8cb6054cd3f7dffe1ce4',
keyProvider: 'creator_priKey',
httpEndpoint: 'http://testnode.dmctech.io:8801',
logger: {
log: null,
error: null
}
});

dmc_client.transact_sync({
actions: [{
account: 'dmc',
name: 'delegatebw',
authorization: [{
actor: 'from', // The name of the account staking the resources.
permission: 'active',
}],
data: {
from: 'from', // The name of the account staking the resources.
receiver: 'Your_Account', // The name of the account receiving the staked resources.
stake_net_quantity: '0.1000 DMC', // The creator stakes DMC for the new account to obtain NET resources.
stake_cpu_quantity: '0.1000 DMC', // The creator stakes DMC for the new account to obtain CPU resources.
transfer: 1 // Indicating whether to transfer the corresponding tokens to the receiver when staking resources. A value of 0 means no token transfer will be made.
},
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
})

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var DMC = require('dmc.js');
var dmc_client = DMC({
chainId: 'c102a8115bef9e4a4e751559aac2cdc2859417e6476f8cb6054cd3f7dffe1ce4',
keyProvider: 'creator_priKey',
httpEndpoint: 'http://testnode.dmctech.io:8801',
logger: {
log: null,
error: null
}
});

dmc_client.transact_sync({
actions: [
{
account: 'dmc',
name: 'newaccount',
authorization: [{
actor: creator,
permission: 'active',
}],
data: {
creator: creator,
name: new_account,
owner: {
threshold: 1,
keys: [{
key: public_key,
weight: 1
}],
accounts: [],
waits: []
},
active: {
threshold: 1,
keys: [{
key: public_key,
weight: 1
}],
accounts: [],
waits: []
},
}
}, {
account: 'dmc',
name: 'buyrambytes',
authorization: [{
actor: creator,
permission: 'active',
}],
data: {
payer: creator,
receiver: new_account,
bytes: bytes
},
},
{
account: 'dmc',
name: 'delegatebw',
authorization: [{
actor: creator,
permission: 'active',
}],
data: {
from: creator,
receiver: new_account,
stake_net_quantity: '0.1000 DMC',
stake_cpu_quantity: '0.1000 DMC',
transfer: false
},
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});

To execute the code and successfully register an account for someone else.

The printed results are as follows (partial excerpt):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"act": {
"account": "dmc",
"name": "newaccount",
"authorization": [
{
"actor": "dmcofficial1",
"permission": "active"
}
],
"data": {
"creator": "dmcofficial1",
"name": "testfhfdfde3",
"owner": {
"threshold": 1,
"keys": [
{
"key": "DM8SQnjqn62A1RgVxxn83BWbNfgnP12dakxHpSH5Ky2HNjEm8rdS",
"weight": 1
}
],
"accounts": [],
"waits": []
},
"active": {
"threshold": 1,
"keys": [
{
"key": "DM8SQnjqn62A1RgVxxn83BWbNfgnP12dakxHpSH5Ky2HNjEm8rdS",
"weight": 1
}
],
"accounts": [],
"waits": []
}
},
"hex_data": "10a271c8ad45914c30545a69b595b1ca01000000010003d391cbe22d7672425d0c65dc72c3f3821b07bd3503f2010e6e4629c3bcf724710100000001000000010003d391cbe22d7672425d0c65dc72c3f3821b07bd3503f2010e6e4629c3bcf7247101000000"
}

Based on the printed information above, it can be seen that the account dmcofficial1 has created an account named testfhfdfde3. The owner of the testfhfdfde3 account can now import the private key into the DMC wallet to access its various functionalities! Click here to download the DMC wallet and get started!