賬戶

什麼是賬戶

生成公私鑰

Tips:生成的公私鑰對需要將私鑰妥善保存,並且切勿向任何人洩漏你的私鑰!請別人幫人註冊 DMC 賬號只需要提供你的公鑰即可,任何以幫忙註冊 DMC 賬號為名索要你的私鑰的創建者都是欺騙者!

使用 dmc.js 的 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('公鑰: %s\n私鑰: %s',pubkey,prikey);

// output:
// 公鑰: DM6smdPjLVZ9rdWfSvHND3xUgAdFq1o9b4yNyRi4KJAid74o7HGR
// 私鑰: 5J2k1YSbjrG4cPEC8QSbqjr4kBbo2JgTjVw4aEqVBBkmWrrD5q1

創建賬戶

新賬戶創建

調用 newaccount 方法和參數名解釋如下:

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", //創建者的賬戶名
permission: 'active',
}],
data: {
creator: "Creator Name", //創建者的賬戶名
name: "Account Name", //被創建者的賬戶名
owner: {
threshold: 1,
keys: [{
key: "Owner Key", //被創建者賬戶 owner 權限公鑰
weight: 1
}],
accounts: [],
waits: []
},
active: {
threshold: 1,
keys: [{
key: "Active Key", //被創建者 active 權限公鑰
weight: 1
}],
accounts: [],
waits: []
},
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});

購買內存

在鏈上存儲賬戶信息是需要消耗內存的,創建者需為被創建者購買內存來存放新賬戶的信息。

調用 buyrambytes 方法和參數名解釋如下:

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', // 創建者的賬戶名
permission: 'active',
}],
data: {
payer: 'from', // 創建者的賬戶名
receiver: 'Receiver Account',//被創建者的賬戶名
bytes: 'bytes' // 購買的內存大小
},
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
})

抵押資源

創建者為被創建者抵押 DMC 獲取 CPU 和 NET ,讓新賬戶能夠進行轉賬。

調用 delegatebw 方法和參數名解釋如下:

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', // 創建者的賬戶名
permission: 'active',
}],
data: {
from: 'from', // 創建者的賬戶名
receiver: 'Your_Account', // 被創建者的賬戶名
stake_net_quantity: '0.1000 DMC', // 創建者為被創建者抵押 DMC 獲取 NET
stake_cpu_quantity: '0.1000 DMC', // 創建者為被創建者抵押 DMC 獲取 CPU
transfer: 1 // 代表抵押資源同時是否將對應通證轉賬給接受者, 0 表示不轉賬
},
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
})

實例

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,
});

執行代碼,即可幫助別人成功註冊賬號。

打印結果如下(部分截取):

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"
}

根據上面的打印信息,可以看到 dmcofficial1 賬號創建了一個名為 testfhfdfde3 的賬號,下面 testfhfdfde3 賬號持有者就可以將私鑰導入到 DMC 錢包中來使用其中的各項功能啦!點擊 下載 DMC 錢包 來獲取 DMC 錢包吧 ~