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

in #witnesslast year

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).

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

Thank you for reading. I'm a witness. You could find more on my site https://steem.fans

I would really appreciate your witness vote! You can vote by AuthSteem. Or open https://steemitwallet.com/~witnesses page, input ety001 to vote.

2.gif

Thank you!

Sort:  

!thumbsup

Hello @ety001! You are the best!


command: !thumbsup is powered by witness @justyy and his contributions are: https://steemyy.com
More commands are coming!

Thank you very much.

Congratulations, you have enabled UVF by @boylikegirl
Common UVF commands:
1.uvf_info
Reply any post use "!uvf_info"
Display your UVF information

Coin Marketplace

STEEM 0.29
TRX 0.12
JST 0.032
BTC 63571.79
ETH 3068.45
USDT 1.00
SBD 3.97