steem-python tips #2 - Create Steem accounts yourself

in #steem-python8 years ago (edited)

Creating accounts


Do you know that you can actually create accounts with 1 STEEM fee and 10 SP delegation? Otherwise, it wouldn't make any sense since, in a decentralized blockchain, we would be bounded to Steemit.

Creating an account is actually an "account_create_with_delegation" operation broadcasted to the network. Creating accounts has a cost because every account needs a little SP to interact with the blockchain. (SP gives voting power and bandwidth allocation to steem accounts)

Steemit does that for you if you are willing to wait for their approval and give up your privacy. (Phone number) But if you want to create an account for your friends, family, you can actually do it yourself without waiting for Steemit's approval.

Also, if you create an account, automatically, you become the recovery account of the created account, which may be better in certain situations.

Account creator script


Out script's main flow should be like this:

  • Get an input with new_account_username, new_account_master_key and creator account.
  • Broadcast an "account_create_with_delegation " operation to the network
  • Get new account's posting, active, owner, memo keys. (both private and public.)

Basic example to create an account:

from steem import Steem
from steem.account import Account
s = Steem(
    nodes=["https://api.steemit.com"],
   keys=["active_key_of_creator_account",]
   )
steemd_instance.create_account(
    new_account,
    delegation_fee_steem="1 STEEM",
    password=new_account_master_key,
    creator=creator_account,
)


Steemd representation of account_create_with_delegation operation.

This script will create the account successfully. But you don't know to get the private keys, yet. (posting, active, owner, memo.) These keys can be obtained with the master key.

The Ultimate Account Creator Script


from steem import Steem
from steembase.account import PasswordKey
def create_account(steemd_instance, new_account, new_account_master_key, creator):
    steemd_instance.create_account(
        new_account,
        delegation_fee_steem="1 STEEM",
        password=new_account_master_key,
        creator=creator,
    )
    keys = {}
    for key_type in ['posting','active','owner','memo']:
        private_key = PasswordKey(
            new_account, new_account_master_key, key_type).get_private_key()
        keys[key_type] = {
            "public": str(private_key.pubkey),
            "private": str(private_key),
        }
    return keys
if __name__ == '__main__':
    s = Steem(nodes=["https://api.steemit.com"],
              keys=["creator_acc_active_wif"])
    keys = create_account(
        s,
        "new_account_username",
        "new_account_master_key",
        "creator_account_username"
    )
    for key, subkeys in keys.items():
        print("Key Type: %s" % key)
        print("Public: %s\nPrivate: %s\n--" % (
            subkeys["public"], subkeys["private"]))

See the script nicely formatted at Github gists.

It should give an output like this when you execute it.

Notes


  • It will cost you 1 STEEM and 10 SP delegation. You can take back the delegation later on and power down the STEEM.

  • Make sure you have picked up a complicated and secure password for the master key. These are similar to brain wallets so it might be ugly if you pick 123456.

  • You need steem-python installed in your local environment to execute this script.

Have fun.

Sort:  

Didn't know this. Thanks for posting helpful information.

Great postings, very important and useful for all steemians, and I say thanks to @emrebeyler for helping steemians.

You got a 4.81% upvote from @buildawhale courtesy of @emrebeyler!
If you believe this post is spam or abuse, please report it to our Discord #abuse channel.

If you want to support our Curation Digest or our Spam & Abuse prevention efforts, please vote @themarkymark as witness.