Creating accounts with dsteem 0.6

in #steemdev4 years ago (edited)

dsteem 0.6

I've spent the better part of this weekend working on dsteem and just published version 0.6.0 to npm. It's pretty much feature complete at this point, but I'm going to wait a while to tag a stable release. I want to get a chance to use it in a couple of projects before cementing the APIs.

One of the reasons I created dsteem was because I felt that the current ecosystem really needs more documentation (that's what the d in dsteem stands for). Starting out I found it difficult to understand how to use the protocol and how the calls should be formatted, especially for the account creation process. So I thought that documenting that process would be useful, as well as a good showcase of what dsteem can do.


There's two ways to create accounts on the steem blockchain, you can either pay the entire account creation fee up front (6 STEEM at the time of writing, more on that later) or you can pay a smaller fee and delegate some of your Steem Power to the new account. This is the method Steemit Inc. uses to create new accounts for users that sign up.

Delegated Steem Power is like a loan, the new account gets to use a portion of your Steem Power but they can not power it down and sell it.

The minimum creation fee is decided by the witnesses, they publish a price that is used to determine the final cost of the account. The median account creation price at the time of writing is 0.2 STEEM. Yes, I just wrote that it cost 6 STEEM but that's because to get the full price you need to multiply the base fee by 30. This can seem arbitrary at first but it will make sense when you understand how the base fee is used to calculate the discount when delegating steem.

Let's start by creating an account without delegation, to do that you first need to prepare some keys for the new account:

const username = 'foo'
const password = 'barman' // ⚠️🔐💩

const ownerKey = PrivateKey.fromLogin(username, password, 'owner')
const activeKey = PrivateKey.fromLogin(username, password, 'active')
const postingKey = PrivateKey.fromLogin(username, password, 'posting')
const memoKey = PrivateKey.fromLogin(username, password, 'memo')

Run on the Playground

As you can see the keys are derived from your username and password, that is why it is a good idea to login on steemit.com with just your posting key.

Steem has three auth levels: owner, active and posting. Posting lets you post content and vote, active lets you transfer money and owner is only used to change the other keys (and itself). The memo key meant for message encryption and is currently not used on steemit.com.

Now we need to wrap the keys in something called an Authority, they can be used for lots of cool stuff like multisig and shared usage of an account, but for now we will just create the most basic authority objects possible for the keys.

const ownerAuth = {
    weight_threshold: 1,
    account_auths: [],
    key_auths: [[ownerKey.createPublic(), 1]]
}
const activeAuth = {
    weight_threshold: 1,
    account_auths: [],
    key_auths: [[activeKey.createPublic(), 1]]
}
const postingAuth = {
    weight_threshold: 1,
    account_auths: [],
    key_auths: [[postingKey.createPublic(), 1]]
}

⚠️

Take extra note that those are the public versions of the keys, the private keys are only ever used to sign transactions!

The first rule of steem is: You don't share your private key. The second rule of steem is: YOU DON'T SHARE YOUR PRIVATE KEY! Third rule of steem: Use strong passwords. Fourth rule: don't store your paper-wallet in a damp space.

That sorted we need to figure out what fee to pay for the new account, we could simply hard-code it to 6 STEEM but that could break if the witnesses arrive at a new consensus or an update to the protocol changes the constants.

So let's do it the proper way. To do that we need to connect to a steem rpc node and get the current witness consensus along with the configuration constants:

const client = new Client('wss://steemd.steemit.com')

const constants = await client.getConfig()
const chainProps = await client.getChainProperties()

const ratio = constants['STEEMIT_CREATE_ACCOUNT_WITH_STEEM_MODIFIER']
const fee = Asset.from(chainProps.account_creation_fee).multiply(ratio)

Run on the Playground

The steem chain properties are median values of what the top 21 witnesses has voted for and besides the account creation fee it also contains the maximum block size and the Steem Dollar interest rate.

There we go, 6 STEEM. Now we have everything we need to create a new account, let's construct an operation we can broadcast to the network:

const op: AccountCreateOperation = ['account_create', {
    creator: 'this-is-you',
    new_account_name: username,
    owner: ownerAuth,
    active: activeAuth,
    posting: postingAuth,
    memo_key: memoKey,
    json_metadata: '',
}]

Now we need to package the operation in a transaction, serialize it and finally sign it with the active authority of creator. That's a bit out of scope for this article so let's just use dsteem's sendOperations helper.

const creatorKey = PrivateKey.from('5rule1rule1rule1rule1')
await client.broadcast.sendOperations([op], creatorKey)

👌

Account created! Easy! 🙂 Let's create another one, with delegation this time. But first I have to let you in on a little secret, Steem Power does not actually exist, it is just a representation of how many STEEM you would have if you withdrew your vesting shares.

The steem blockchain uses the VESTS symbol to represent your vesting shares in the platform.

So to figure out how much delegation is needed we need to get the current vesting share price:

const props = await client.database.getDynamicGlobalProperties()
const sharePrice = Price.from({
    base: props.total_vesting_shares,
    quote: props.total_vesting_fund_steem
})

💰

The creation fee is discounted on a 1 to 5 basis for delegated steem, e.g. 30 delegated steem is worth 6 steem. With that info we can calculate how many VESTS we need to delegate, let's say we want to pay 0.5 STEEM as a creation fee and the rest as delegation:

const fee = Asset.from('0.500 STEEM')
const ratio = constants['STEEMIT_CREATE_ACCOUNT_DELEGATION_RATIO']
const modifier = constants['STEEMIT_CREATE_ACCOUNT_WITH_STEEM_MODIFIER']

const targetDelegation = sharePrice.convert(
    creationFee.multiply(modifier * ratio)
)
const delegation = targetDelegation.subtract(
    sharePrice.convert(fee.multiply(ratio))
)

Run on the Playground

Now we can broadcast the operation just like before, just using the account_create_with_delegation operation instead of account_create. I'll leave that as an exercise for the reader 🙂.


But you don't really need to know all this to use dsteem, it does it for you. Creating a new account is as simple as:

await client.broadcast.createAccount({
    username: 'foo', password: 'barman', creator: 'someone'
}, someonesActiveKey)

Run on the Playground

That creates the keys, figures out the correct fee and delegation amounts and broadcasts the operation. See the method's documentation for more info.

The more you know... 🐢


GitHub Repository | API Documentation | Coding Playground | Live Demo

Sort:  

Considering SteemJS-Lib by @svk is practically abandoned, I may re-write my price feed to use dsteem.

A few questions:

  1. Does it handle disconnects smoothly? i.e. automatically reconnect without just breaking
  2. Does it support other chains? e.g. GOLOS, PeerPlays
  3. Is there a browser version ready built?
  4. What versions of NodeJS does it run on?

Awesome, would love to see some more real-world usage!

  1. Yep, it even has a configurable exponential backoff. But you do need to handle retries, if a command times out for example.
  2. I think so, It works well running against my testnet which has a custom chain id and address prefix.
  3. Yep, check the ./dist/ folder in the github repo
  4. I'm testing against node 7 and 8, will probably work with 6 as well.

@someguy123 - Not to take any steem away from dsteem (pun intended), but the steem-js library is actually still actively developed at it's official home on the steemit github here: https://github.com/steemit/steem-js

It's actually what condenser uses for the live site today - the one on svk's github is outdated. It handles disconnects smoothly, supports alternative chains (at least golos), and the browser based version is ready and built.

With that being said, diversity in the steem ecosystem is a good thing and dsteem is pretty cool too :)

steem-js != steemjs-lib

They work completely differently to each other. Originally the official steemit one had practically no documentation, and I believe it lacked the functions I needed.

Of course if it's improved now, then maybe I'll try it out.

Great post! The project is interesting. I am very interested. At this point I agree with you.

i almost forgot about my peerplay tokens is that a website yet? is perry plays up nd running? will they hve a blocktrades type feature where u can sell ur peerplay tokens or will peerplays be on bittrex like golos is? or do u have any idea?

Anyway this whole post is GREAT @almost-digital you demystified the whole account creation process to explain to people why it costs 6 steem to generate an account and i am confident that it will not become a bottleneck and steem will be able to grow very fast and we will have no problem hitting 1 million actual human active users by next year and a nice $5 price of steem by the end of this year, It should be $10 if people knew how valuable the steem blockchain really wayt

imagine if facebook creatd thir own hardfork of steem and used it for facecoin? It would be HUGE! steem's DPOS delegated proof oif stake system is just the most efficient crypto cutrrency social media system out there and there is nothing like it and there will BE nothing like it!

steem happened because of the Crypto sphere! a world of self employed financially independent people came together and made something happen at the perfect time and crypto will only grow and eat up all the worlds fiat. Hyperinflation wont affect steemit. our steem iwll be so precious just like Bitcoin.../steem is going to become a very valuable altcoin

appreciate your services dude ;)

Appreciate your services dude ;)

an important thing to know is that usernames are alphamnumerical only.

Took me a few tries and headscratching 2 days ago to get this.

Took me a few tries and headscratching 2 days ago to get this.

Happens to me too :)

Awesome, but still thinking Steemit as itself should consider to fix this problem. I know that it cost 9 STEEM to create a new account, but again, i agree with Steemit to charge us a little percentage for all author and curation rewards to cover this account creation cost.

Awesome documentation!!!
Tried it on a friends MacBook and it is still loading...
Is it normal to take some time?

Thanks! You're talking about the playground right?

I've seen that as well, sometimes the coding editor does not load in Safari. Reloading the page usually fixes it.

it now works, but i get a message, that the key is wrong...

Great job buy how different it is compared to steem-js? I feel it is much more appreciated to help steem-js develops better documentation and everyone use that instead of creating new packages. Just my 2 cents here.

It's faster, written in TypeScript and has 99% test coverage along with integration tests against a testnet. I'm also aiming to simplify the steemd APIs instead of just providing a 1:1 call wrapper as shown here with the account creation.

But I understand your point. I started out using steem-js and even have a commit or two in the project but to be honest I didn't like the smell of the code... and barging in to a established project and saying "Hi! I'm new here. I'm going to rewrite all your things in my own opinionated way" usually don't go over well :) I also recently wrote a WebSocket RPC client that I could reuse a lot of code from.

Great contributions on your side. I think having a 1:1 call wrapper is necessary to have a low-level API available for different use cases but I wished we could all build new high level APIs on top of that one single well maintained code.

Even so, it's a great effort on your side and maybe it's better to use a well tested code like yours for new apps. I find it a little risky for new devs to join since most of the sample codes are for steem-js and it makes your job much harder to promote your solution.

But I understand your point. I started out using steem-js and even have a commit or two in the project but to be honest I didn't like the smell of the code..

This sounds much cheaper than making accounts via anon-steem

I've made a tool to create accounts here: https://account.steem.vc
It does not do delegation yet so you every account cost 6 STEEM (that will be steem power in the new account)

Nice example. Hope you can come out with more examples. I am wondering how would one get the recent transfers for an account (the data on the wallet page) ?

Thanks! There isn't a helper to get the account history in dsteem yet but here's how you do it manually:

https://playground.steem.vc/@^0.6.0#c182038ce97d3d4d283b50fd87ed0190

thanks a lot

Thanks for putting this together! Resteemed and will definately play around with this this weekend when I have some free time

Awesome! Let me know how it goes :)

Will do! :)

amazing work

Really cool project. Im playing with it now

Nice job

Please add syntax highlighting to steemit!

great stuff - will check that out soonish this weekend :)

thanks =9

way over my head

this is great,thank you @almost-digital.

The project as you work is worthy of always getting support from anyone, because the project is very helpful for little whales like me to get a whale mom to grow up soon.

This project or similar projects as it already is:
#steemdev #steemit #dsteem #esteem # steem-js or something else.

I always support anyone who always provides benefits for many people.

regard the little whale @madcool the mother's seeker.

very beautiful post...this is a nice project...l joined steemit not long ago but am really loving every bit of your post...am in for this project too..upvoted

what a great project done here, i also learned programming before and i love your work. Looking forward for your next work so i can learn something from you.

wowww..it's so amazing post...thanks for share..

Very excellent site I wish you more excellence and success

A place more beautiful than my dear brother

Its mean basically you are software developer??

lol! tldr; I'm a swoftware developer :D

Sounds exceptionally complicated..

You can Follow me for the latest Technology Related News and Articles.. Thank You...

Interesting post. Worth reading it. Thank you for sharing.

amazing work info

Wow good information on one post, I wait for your next posting

Good job. Thank you!

Nice post,Thank you for sharing.

Hello nice post! I already upvote, reesteem and follow you please do the same to help me grow as well!

Follow for Follow 😊

Great news

Ty to share upvote and follow you

nice
great post
thank you for your effort

I like your post, and I will wait for your next posting

Thanks for your information
I want to try it

Gracias, esta versión está bastante estable. Saludos!!

Great job. Thank you!!

very great post!

There's two ways to create accounts on the steem blockchain, you can either pay the entire account creation fee up front (6 STEEM at the time of writing, more on that later) or you can pay a smaller fee and delegate some of your Steem Power to the new account. This is the method Steemit Inc. uses to create new accounts for users that sign up @almost-digital

is post private key different from the master key?

Interesting. Have you thought about making a video for the severely techno illiterate?

Good....doest dsteem influence on steemit account performance if we activate it. I need more information about it because it seems not free. But it's ok as long as i know it clearly at first

One of the reasons I created dsteem was because I felt that the current ecosystem really needs more documentation (that's what the d in dsteem stands for). Starting out I found it difficult to understand how to use the protocol and how the calls should be formatted, especially for the account creation process. So I thought that documenting that process would be useful, as well as a good showcase of what dsteem can do.

Awesome project,
Thanks for sharing

Nice work bro n thanks for comments

Priority: try to get maximum Steem Power, and invest with steem.

Steem is going to occupy big space.

Thank you very much for creating this unique Steem application.

Just stumbled upon dsteem, thanks so much for creating this! This is exactly what I was looking for to better understand how the Steem API works, I think this will be a great help to me. And now I also finally have a good excuse to check out TypeScript :)

Awesome, let me know how it goes :)

This is the best post about user creation I have seen to date. You just made my project task of creating a new user so much easier, and a future feature in our app much more plausible.

We will be switching our project over to dsteem before we write our next remote call!

Cheers,
@kellyjanderson

Awesome, thanks! I'm happy that it helped you

Wow good information on one post, I wait for your next posting

Interesting. I should usually read it again

Great post @almost-digital. Thanks for shedding some light on your project. Im personally looking out for dsteem

Not related to the topic but can someone please clarify that if my account is hacked and I want to recover it would I need the phone number with which I registered this account or not? Thank you in advance!

Great post! The project is interesting . At this point I agree with you.

thanks for sharring this good information

Are there any other libraries for other languages?

I was wondering if there's some list somewhere that you could link me. I found one for ruby: https://github.com/inertia186/radiator
is there some central list someplace?

doesnt this make it easy for people to create 100+ spam accounts ?

Only if they are willing to pay 600 STEEM+

thank you so much this post was really really helpful i understand a lot better now thank you

nice
follow me @newzifa

so many people in here just commenting to get upvotes without even reading what the writer has to say. so poor

Крутые новости а у нас все тихо

This is good to know, thanks a lot for the update. Upped.
In addition to my last comment, feel free to join the conversation in my new post about future of steem...it will motivate you more about steem . More success to you.

good post men

Thank you @almost-digital you have done good job.

very nice

i am new in esteem. please come home to stop at my update. Please help me @almost-digital

Great. Thanks for sharing. I vote for you and begin to follow you. And Resteemed... ☺♥

Great Post :)

i will try it , nice

I has follow, upvote and resteem your post, i hope you're following me too and do what i do it for you brother, i'll be back thanks

Best regards
@mukhtar.juned

#indonesia

good informative post :-)

dSteem sounds like an interesting project

This is great! Very Interesting! I hope to see more improvements in the future..Very well done.. thanks!

I love the idea.It looks you have quite a bit of work cut out for you still, but the project sounds really good. Keep up the good work and keep us posted

Love the post and trying to work out how I can run the code, I use to be a techie head a little bit of java and sql but this was a very long time ago. So not really any great programming but you have definitely made me curious again. How can I run this @almost-digital may be a silly question. But you won't know unless you ask. Following and upvoting thanks for inspiring my technical juices.

It's much easier to create accounts like this, I'll try

Hi, I created some accounts with client.broadcast.createAccount but I don't seem to be able to remove my delegation from those users. I used delegateVestingShares to delegate 0.000000 to user rgb14, the delegation got recorded in the blockchain but I still have delegation coming off my account.

AWESOME !!! , great post buddy,, keep it @almost-digital
if you like about cryptocurrency, visit my post and please help be upvote and resteem please.
https://steemit.com/cryptocurrency/@wahyue/review-of-the-scam-webdengi

same other channal
from https://steemit.com/@cheetah
https://busy.org/@cheetah
Okay, I have banned your channal in 5 dyas

Warning! This user is on my black list, likely as a known plagiarist, spammer or ID thief. Please be cautious with this post!
To get off this list, please chat with us in the #steemitabuse-appeals channel in steemit.chat.

same other channal
from https://steemit.com/@cheetah
https://busy.org/@cheetah
Okay, I have banned your channal in 5 dyas

Warning! This user is on my black list, likely as a known plagiarist, spammer or ID thief. Please be cautious with this post!
To get off this list, please chat with us in the #steemitabuse-appeals channel in steemit.chat.

Resteem your post to 1000+ followers for only 0.5 SBD or Steem)

Just send 0.5 SBD or steem to @steemvote (URL as memo)

New Followers get 0.001 SBD$ and an upvote for free!!

Just follow @steemvote and...

  • we follow back
  • send you 0.001 SBD to your wallet

Why the fuck are people upvoting this blatant spam?

same other channal
from https://steemit.com/@cheetah
https://busy.org/@cheetah
Okay, I have banned your channal in 5 dyas

Copyright: https://steemit.com/created
Every Post New
get a collect a username and post on your account

Warning! This user is on my black list, likely as a known plagiarist, spammer or ID thief. Please be cautious with this post!
To get off this list, please chat with us in the #steemitabuse-appeals channel in steemit.chat.

same other channal
from https://steemit.com/@cheetah
Okay, I have banned your channal in 5 dyas

Warning! This user is on my black list, likely as a known plagiarist, spammer or ID thief. Please be cautious with this post!
To get off this list, please chat with us in the #steemitabuse-appeals channel in steemit.chat.

an important thing to know is that usernames are alphamnumerical only.

Took me a few tries and headscratching 2 days ago to get this.

wow this is great...so from what I gather from this in short you have just made it much easier to create accounts?... great work and thank you @almost-digita

Hello steemian @almost-digital
I am here to help show your blog to more people by resteeming your post
Your post was picked from the feeds, as part of the advertisment campaign for @steempowerbot
@steempowerbot is meant to help minnows get noticed by re-steeming their posts

To use the bot, one must be following us, and then make a transaction where the memo is the url of the post.

We are offering #free resteem service now.
For us to see your post use the tag #blessaminnowtoday
You can help us spread the word

from https://steemit.com/@cheetah
Okay, I have banned your channal in 5 dyas

Warning! This user is on my black list, likely as a known plagiarist, spammer or ID thief. Please be cautious with this post!
To get off this list, please chat with us in the #steemitabuse-appeals channel in steemit.chat.

wow this is great...so from what I gather from this in short you have just made it much easier to create accounts?... great work and thank you @almost-digital.

Thanks! Yeah, easier for developers to make tools to make new accounts at any rate :)

We have some great people working on steemit, for sure, and many more that will add to it coming very soon. Which is why I am here to learn and do my part in time.

I heard that after the next hardfork, they will have a solution for account creation bottleneck, and that then there will be millionsof dollars of advertising marketing money spoent to promote steemit, and that right now since it is a liability to get new users in and since it costs money to make new acounts, over $1 per nwew account then millions of new users is just anotehr liability and hard fork will fix that! no erason they can generate a bunch of new accounts free, BASICALLY manually adding a bunch of new accounts? or maybe theyll change the way steemit creates accounts? I know right now they got it down to like 2 or 3 steem to createa new acount but they could create abunch of free accounts via consensus , without inflating price of steem, it is complex the way it all works because peopel arent used to decentralized websites like this and their intricacies!

anyway Im happy to hear how MOSt of the negtive rumors about how steem has too many problems, is not true, and stemit inc has a lot of cool suprises for us, BUT the steemit inc guys on discord expressed his concenrn that more siutres arent bneing created like busy,org and how they dont wanna be the only site to interface with steem blockchaina nd how eneed peopel to amke their own website sto access steem bvloickchain

we really do need more clones of steemit but we need more than clones, we ned seperate website sthat just use stem bloickchain and i think we need more apps , and @zappl wil be one, but we need more!

I think thinghs will be fine, ytheers enough money to hire enough people to get al of these thinsg done, and steem willonly grow

so the one thing we all can do is just buy mroe steem and power it up as steempower! you wont regret it and the nmoney you can all amke off curation and comments and posting once u have lots of steempower and make lots fo followers will realy becme worth it!