Demo code about how to create a new account by Steem JS SDK

Here is the demo code which displays how to create a new account with Steem JS SDK in two different ways ( by taking fee or by taking interests of claimed account).

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
const steem = require('steem')

const creator = 'test1';
const activeWif = '';
const newUsername = 'test2';
const newPasswd = 'P5KZS6bp8sVxxxxxxxxxD48jwBKxshpNZxsYnJ';
const fee = '3.000 STEEM'

const newKeys = steem.auth.getPrivateKeys(newUsername, newPasswd, ['owner', 'active', 'posting', 'memo']);
console.log(newKeys);

const weightThreshold = 1;
const accountAuths = [];
const owner = {
weight_threshold: weightThreshold,
account_auths: accountAuths,
key_auths: [[newKeys.ownerPubkey, 1]],
};
const active = {
weight_threshold: weightThreshold,
account_auths: accountAuths,
key_auths: [[newKeys.activePubkey, 1]],
};
const posting = {
weight_threshold: weightThreshold,
account_auths: accountAuths,
key_auths: [[newKeys.postingPubkey, 1]],
};
const memoKey = newKeys.memoPubkey;

// create a new user by creator with 3.000 STEEM fee
steem.broadcast.accountCreate(activeWif, fee, creator, newUsername, owner, active, posting, memoKey, '{}', function(err, result) {
console.log(err, result);
});

// create a new user by creator with claimed account interests
const op = [
"create_claimed_account",
{
"creator": creator,
"new_account_name": newUsername,
"owner": owner,
"active": active,
"posting": posting,
"memo_key": memoKey,
"json_metadata": "{}"
}
];
const tx = {
operations: [op],
};
steem.broadcast.send(tx, [activeWif], function(err, result) {
console.log(err, result);
});