Steem Tutorials Are Severely Lacking (Where is Hello World?)

in #tutorial6 years ago


bang head programming.gif

It is such a daunting task to learn a new programming language and try to figure out wtf is going on. Relative to Steem API programming, this frustration is magnified ten fold. Why? This technology is so new. Nothing is streamlined. Tutorials don't even exist for the task I'm trying to accomplish.


hello world.jpg

Uh... Hello World?

Seriously though, where is the "Hello World!" tutorial? It doesn't even exist. If you go to Steem API tutorials the first thing listed talks about Node.JS and how to import a blog feed. Yeah, this isn't what I want.

"Hello World" is how every tutorial starts. Learning to program requires baby steps. The opening baby step for any language or API is to print hello world to the screen. In the context of Steem API it would be creating a post that says "Hello World". Well? Where is it? Woof.

I've found several old tutorials on Steemit that try to get you started, but they all use the Steem-JS library. This library isn't even being used anymore. You're supposed to use DSteem.

The more I learn about Node.JS the more I realize this isn't what I'm looking for. I'm not looking to attach a centralized server to the Steem blockchain. I'm looking to use the Steem blockchain as the server itself in a decentralized manner. Apparently, this concept is so foreign that finding instructions on how to do it is nearly impossible.

This issue that I'm having really makes no sense to me. At first I was thinking that Node.JS was required in order to talk to the blockchain. However, when I visited https://jnordberg.github.io/dsteem/ I came across this code:

<script src="https://unpkg.com/dsteem@latest/dist/dsteem.js"></script>
<script>
    var client = new dsteem.Client('https://api.steemit.com')
    client.database.getDiscussions('trending', {tag: 'writing', limit: 1}).then(function(discussions){
        document.body.innerHTML += '<h1>' + discussions[0].title + '</h1>'
        document.body.innerHTML += '<h2>by ' + discussions[0].author + '</h2>'
        document.body.innerHTML += '<pre style="white-space: pre-wrap">' + discussions[0].body + '</pre>'
    })
</script>

I was very surprised that this code actually works. All you have to do is copy and paste it into an HTML file. It grabs the top trending post in the "writing" category and displays it. You can toy with the code by changing the "tag" string and the 'trending' string (to 'new' or 'hot'... jk 'new' doesn't work it's actually called 'created'). When you do this the code will display the first post it finds in that category correctly. It's nice that at least something works.

javascript steem api return.png

So it's obvious that you can indeed access the dsteem library directly with JavaScript without the need for node.js. Again, I'm not looking to host a server. I just want simple access to the blockchain:

  1. Posting
  2. Upvoting
  3. Retrieving posts
  4. Deleting posts

This is really the only functionality I'm going to need 99% of the time, but there doesn't seem to be any kind of guidance to accomplish this directly with JavaScript. I'm thoroughly annoyed.

There's no shame at starting at square one... so I guess I'll be the one to create this tutorial unless someone comes along and rescues me.

@fulltimegeek? @aggroed? @krnel? @timcliff?
Save me from my own ignorance please 👍

8 hours later

I wrote this last night and I'm still at it. All I'm trying to do is upvote a comment.

Here's the code I have to work with from the dsteem github:

var dsteem = require('dsteem')

var client = new dsteem.Client('https://api.steemit.com')
var key = dsteem.PrivateKey.fromLogin('username', 'password', 'posting')

client.broadcast.vote({
    voter: 'username',
    author: 'almost-digital',
    permlink: 'dsteem-is-the-best',
    weight: 10000
}, key).then(function(result){
   console.log('Included in block: ' + result.block_num)
}, function(error) {
   console.error(error)
})

Except you can't "require('dsteem')" because that is a Node.JS thing. So I tried removing it and adding

 <script src="https://unpkg.com/dsteem@latest/dist/dsteem.js"></script>

This gives me the error that my permissions aren't working (signing with the private key)

https://stackoverflow.com/questions/23603514/javascript-require-function-giving-referenceerror-require-is-not-defined

Now I'm trying to use RequireJS so that the "require('dsteem')" line won't throw an error, but that just throws another error:

https://stackoverflow.com/questions/17446844/dynamic-require-in-requirejs-getting-module-name-has-not-been-loaded-yet-for-c

Seriously, all I'm trying to do is upvote a permlink with JavaScript and there are no instructions on how to accomplish the basics. WTF Steemit Inc? I'm not mad at all. Programming is always like this, but if we want to onboard as many programmers as possible it's stupid stuff like this that is going to turn developers away. Not me though, this place is a flippin' gold mine.

Sort:  

Seriously, all I'm trying to do is upvote a permlink with JavaScript and there are no instructions on how to accomplish the basics.

<script src="https://unpkg.com/dsteem@latest/dist/dsteem.js"></script>
<script>
var client = new dsteem.Client('https://api.steemit.com')
var key = dsteem.PrivateKey.fromLogin('bigpun', 'master-password-goes-here', 'posting')

client.broadcast.vote({
voter: 'bigpun',
author: 'edicted',
permlink: 'steem-tutorials-are-severely-lacking-where-is-hello-world',
weight: 10000}, key).then(function(result){
      document.write('Included in block: ' + result.block_num)
}, function(error) {
      document.write(error)
})
</script>

Seriously though? I have to put my master password in there?

I have zero experience with that api except for that code I just shared. There is probably another api call that doesn't require the master.

yeah well it totally worked... my brain would not allow me to even test the master password... that seems really really dumb.

I dug around a bit and found the PrivateKey.fromString() call 😊

var key = dsteem.PrivateKey.fromString('posting-key-goes-here')

much appreciated! works!

I'm glad my tech support worked :) ... time to celebrate with a nerd rap

What API are you using?

I made my own.

For reading the blockchain it's quite easy to do. But, when you start introducing private keys and having to sign a message, that's a whole nother level of complexity.

"Hello world" is for technologies. Feed is the hello world for API.

On a side note this guy jnordberg (@almost-digital) is a bad ass. He basically created DSteem by himself which turned out to be so much better than Steemit Inc's SteemJS that now everyone uses it.

Looks like even though I'm creating a key the key isn't working:

var key = dsteem.PrivateKey.fromLogin('edicted', MY_POSTING_KEY, 'posting')

I add the key to the broadcast but I get this error:

missing posting authority.png

Seriously why... FML this is annoying.

The most annoying thing about all of this is that I don't even know if what I'm trying to do is impossible. Just trying to broadcast an action on the blockchain using nothing but JavaScript... doesn't seem like it should be an issue... yet here I am.

Its not difficult. Its literally one line of code to vote on a post:

steem.broadcast.vote(private_posting_key, voter, author, permlink, weight, callback);

Nice, so can you tell me why:

var key = dsteem.PrivateKey.fromLogin('edicted', MY_POSTING_KEY, 'posting')

client.broadcast.vote({
    voter: 'edicted',
    author: 'edicted',
    permlink: 're-edicted-steem-tutorials-are-severely-lacking-where-is-hello-world-20180829t190313889z',
    weight: 100
}, key).then(function(result){
   console.log('Included in block: ' + result.block_num)
}, function(error) {
   console.error(error)
})

Doesn't work?

var key = dsteem.PrivateKey.fromLogin('edicted', MY_POSTING_KEY, 'posting')

Try printing out key here. I think that would be wrong.

Got it working with the master key... seems like a really foolish thing to require.

Since you passed posting as third argument, it should have worked. Are you sure you weren't passing public posting key?

100% sure, I use my keys correctly all the time. It only works with master as far as I can tell.

In fact I just logged out and logged back in with the posting key I was using just to make sure.

Probably a bug then. Steem api works with posting key.

This is your public posting key: STM7KtxFtRj4jXcvmvbifcAzh1rXnBWJiGuTeZAyWnKBKBoZerT1G

yeah all private keys start with a 5. master password starts with a P

grab your private posting key directly from on steemit and pass that.

This stuff looks complicated lol I haven’t even tried writing or looking at script yet. I see that others have helped which is good but I agree there is a lack of good tutorials here.

I know the tutorials are underwhelming to say the least, but you definitely learn a lot through raw trial and error and slowly grinding out code then someone giving you the answer. The higher learning curve gives you an advantage over those that decide not to take on the challenge.

Coin Marketplace

STEEM 0.32
TRX 0.12
JST 0.034
BTC 64664.11
ETH 3166.18
USDT 1.00
SBD 4.11