How to create a new STEEM account by using another account as the creator (javascript)

in #programming8 years ago (edited)
On STEEM every user needs to have a _parent_ user, called the creator. The most common way of creating a new user is by registering on steemit.com. In this case, your _creator_ will be @steem.

If you already have a STEEM account, you can choose to create a new user with that account as the creator.
Here I will explain how to do it with javascript using the steem and dsteem packages. (If you use npm, you can install them usign npm i steem dsteem)

(In the past there was another way to create new users, using PoW mining. Now this cannot be done anymore)

Import the library

First, you need to import the libraries. I will assume you use node to execute your code, so you can just import the libraries like this:

var steem = require('steem');
var Asset = require('dsteem').Asset;

Constants

Let's define now a few constants.
You will need the account name and the private key (active or owner) of the creator account.
Then, you can choose a new name for your newly created account, and a password for it.

var creator = 'your account name';
var creatorWif = 'your account active or owner private key';

var newAccountName = 'name of the new account';
var newAccountPassword = 'password for the new account';

The actual code!

This is the code you need to execute:

var publicKeys = steem.auth.generateKeys(newAccountName, newAccountPassword, ['posting', 'owner', 'active', 'memo']);

var owner = {
    weight_threshold: 1,
    account_auths: [],
    key_auths: [[publicKeys.owner, 1]]
};
var active = {
    weight_threshold: 1,
    account_auths: [],
    key_auths: [[publicKeys.active, 1]]
};
var posting = {
    weight_threshold: 1,
    account_auths: [],
    key_auths: [[publicKeys.posting, 1]]
};


steem.api.getConfig(function(err, config) {
  if(err){
    console.log(err, config);
    throw new Error(err);
  }

  steem.api.getChainProperties(function(err2, chainProps) {
    if(err2){
      console.log(err2, chainProps);
      throw new Error(err2);
    }

    var ratio = config['STEEMIT_CREATE_ACCOUNT_WITH_STEEM_MODIFIER'];
    var fee = Asset.from(chainProps.account_creation_fee).multiply(ratio);

    var feeString = fee.toString();
    var jsonMetadata = '';

    steem.broadcast.accountCreate(creatorWif, feeString, creator, 
                newAccountName, owner, active, posting, publicKeys.memo, 
                jsonMetadata, function(err, result) {
      console.log(err, result);
    });
  });
});

That's it! Just be sure to have at least 6 STEEM on your account, that will be transfered to your new account as SP. (You need at least that in order to be able to use the account)

Hope you like the post!
Let me know in the comments if you have any question.

Sort:  

is there a way to do this with out the command line? Like via steemit.com?
How do you get the command line version of steemit any way?

Nice trick! :-) Is that code bug or system feature?

so you say that I need to have at least 6 Steems in my account to create a new account.
So if I have an app that uses steem blockchain and I want to allow users to create account against my account. - Would each new account cost me 6 steems?
Is there a way to do this without paying?
How about if i run my own Steem node?
thanks in advance for your help

Coin Marketplace

STEEM 0.12
TRX 0.33
JST 0.032
BTC 114262.85
ETH 4161.33
USDT 1.00
SBD 0.78