Steemsnippets : discounted accounts update

in #utopian-io7 years ago (edited)

steemsnippets.png

It has been a while since I've updated this repository, this has mainly been due to the fact that I covered a good part of steem-js basic functions and because the awesome https://github.com/steemit/devportal-tutorials-js has been producing some great educational content so I felt that steemsnippets was not as important as before.

If you are unfamiliar with steemsnippets I encourage you to read the genesis post : https://steemit.com/programming/@howo/introducting-steemsnippets

And to check out the repository : https://github.com/drov0/steemsnippets

Buuut hf20 came and some new stuff needs to be covered, and since I had to figure them out I was like "well let's write a few snippets while I'm at it".

As a side note, I am ditching steem-js for the more modern dsteem and am slowly converting all of my projects, so expect most of my current and future snippets to use dsteem.

This update focuses mostly on a great new feature that was brought by hf20 : discounted accounts, you can read all about them in this steemitblog post. But do bear in mind that you need to be a relatively big stakeholder to hope to claim more than like an account per few days, if you are curious about the costs, I suggest you to look at this great page by @holger80 https://beempy.com/resource_costs and your account on steemd to try to see how much of your ressource credits this will cost you.

Claim discounted accounts

Creating a discounted account works in two steps : first you claim discounted accounts, these are not named and will never expire, you can try to claim as much as you want. For instance @pharesim got 789 as of today.

The snippet can be found here : https://github.com/drov0/steemsnippets/blob/master/dsteem/claim_account/claim_account.js

**
 * claims a discounted account.
 * @param {String} creator - Name of the account that will claim the discounted account.
 * @param {String} active_key - Active key of the creator account
 */
function claim_account(creator, active_key)
{
    return new Promise(resolve => {
        const wif = dsteem.PrivateKey.fromString(active_key);

    const fee = dsteem.Asset.from(0, 'STEEM');

    const op = [
        'claim_account',
        {
            creator: creator,
            extensions: [],
            fee: fee
        }];

    client.broadcast.sendOperations([op], wif).then(function (result) {
        console.log('Included in block: ' + result.block_num)
        resolve("=");
    }, function (error) {
        console.error(error);
        resolve("-");
    });
});
}

This is pretty straightforward huh ?

Create a discounted account

Once you have one or more claimed account, you can use them to create an account for "free" (technically you paid resource credits)

The snippet can be found here : https://github.com/drov0/steemsnippets/blob/master/dsteem/create_discounted_account/create_discounted_account.js

/**
 * Creates a discounted account, note that you need to claim discounted accounts before being able to create them this way.
 * @param {String} creator - Name of the account that will create the new account. This account must have at least one claimed discounted account.
 * @param {String} active_key - Active key of the creator account
 * @param {String} username - username of the account to be created
 * @param {String} password - password of the account to be created.
 */
function create_discounted_account(creator, active_key, username, password)
{
    return new Promise(resolve => {
        const wif = dsteem.PrivateKey.fromString(active_key);

        const prefix = client.addressPrefix;

        const ownerKey = dsteem.PrivateKey.fromLogin(username, password, 'owner').createPublic(prefix);
        let owner = dsteem.Authority.from(ownerKey);
        const activeKey = dsteem.PrivateKey.fromLogin(username, password, 'active').createPublic(prefix);
        let active = dsteem.Authority.from(activeKey);
        const postingKey = dsteem.PrivateKey.fromLogin(username, password, 'posting').createPublic(prefix);
        let posting = dsteem.Authority.from(postingKey);
        let memo_key = dsteem.PrivateKey.fromLogin(username, password, 'memo').createPublic(prefix);

        const metadata =  {date: new Date()};

        const create_op = [
            'create_claimed_account',
            {
                active,
                creator,
                extensions: [],
                json_metadata: metadata ? JSON.stringify(metadata) : '',
                memo_key,
                new_account_name: username,
                owner,
                posting,
            }
        ];


    client.broadcast.sendOperations([create_op], wif).then(function (result) {
        console.log('Included in block: ' + result.block_num);
        resolve("=");
    }, function (error) {
        console.error(error);
        resolve("-");
    });
});
}

I made sure to handle most of the complexity from within the function so you only have to put the account from which you claimed the accounts, it's active key, and then the new user's username and his password and boom you're done.

As a side note, there are no requirements on the password but this password will secure the funds of that account so try to put a strong one alright ?

Conclusion

And that's about it ! Now you can easily run an account creation service, just claim accounts whenever you have rcs to spare and when someone comes to you to create an account, create it using those.

As a side note https://steemd.com/@teststeempress this is a discounted account that I created.

Note how it has 0 sp, so no voting power. yet it has some resource credits, that's because that account was credited the amount of resource credits that would normally be burned to create an account, and as of today the consensus sits at 3 STEEM. And with today's rc costs, this allows this account to make around 3 posts/comments per week so if you want to create an account for a friend make sure to delegate to them a bit if you want to allow them to transact a bit, or upvote them to make them self sufficient.

That's all for today folks, see you around :)

Sort:  

Thanks for the contribution, @howo! Looks like a handy little script for people wanting to create discounted accounts with JavaScript. There have been a few contributions like this popping up (steeminvite by @pharesim and Infestor by @emrebeyler) which is cool to see.

Since this project is more based on helping out and educating developers on the Steem blockchain (I think), maybe you could consider writing tutorials about stuff like this as well?


Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thanks :) I thought about writing tutorials but I don't really have the time to write and maintain them, I would rather just give snippets that people can learn from.

Completely understandable!

Thank you for your review, @amosbastian!

So far this week you've reviewed 27 contributions. Keep up the good work!

I have been looking around for a while to find out how this actually works and you explained it perfectly. Thanks for explaining this!

Hello! Your post has been resteemed and upvoted by @ilovecoding because we love coding! Keep up good work! Consider upvoting this comment to support the @ilovecoding and increase your future rewards! ^_^ Steem On!

Reply !stop to disable the comment. Thanks!

Very wonderful updates my friend
I hope you will be useful to all
Thank you for your efforts

@howo, In my opinion you've mentioned some important points specifically i am talking about the New Account Creations. And yes, the big Stakeholders can effectively create the new accounts and mainly DAPPS and i strongly believe that we will going to see the Potential Users because now every action is backed with an Cost so every action will be backed with the more effectivity. Keep up the great work.

Wishing you an great day and stay blessed. 🙂

Hi @howo!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @howo!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!