create account

Write a Steemit Web App: Part 11 - Posting Content by jfollas

View this thread on: hive.blogpeakd.comecency.com
· @jfollas · (edited)
$77.93
Write a Steemit Web App: Part 11 - Posting Content
_(Previous Post: [Part 10](/@jfollas/write-a-steemit-web-app-part-10-retrieving-comments-with-getcontentreplies))_

Previously in this series, we learned how to fetch content (blog posts and replies) from the Steemit blockchain using Steem.js. How would a web app submit new content to Steemit?

# Introducing `steem.broadcast.comment`
When posting content, there is only one Steem.js function to know: `steem.broadcast.comment`. This is used to both create new blog posts and reply to content written by other people:

```javascript
steem.broadcast.comment (
    private_posting_wif,  // Steemit.com Wallet -> Permissions -> Show Private Key (for Posting)
    parent_author,        // empty for new blog post 
    parent_permlink,      // main tag for new blog post
    author,               // same user the private_posting_key is for
    permlink,             // a slug (lowercase 'a'-'z', '0'-'9', and '-', min 1 character, max 255 characters)
    title,                // human-readable title
    body,                 // body of the post or comment
    json_metadata         // arbitrary metadata
)
```

## New Blog Posts
For new blog posts, use an empty string for `parent_author` and use the post's main Tag (Category) as the `parent_permlink`. 

It is up to your app to create the slug that will be used as the `permlink`. Steemit requires that the slug be lowercase and only numbers, letters, and the '-' dash characters be in the slug string. The length of the slug must be between 1 and 255 characters total.

The `json_metadata` argument can be either an object literal, or JSON string. While not well documented, it appears that Steemit needs certain data to appear in the metadata for a new post. 

As an example, let's look at the metadata that was submitted with [Part 10's Blog Post](https://steemdb.com/steemdev/@jfollas/write-a-steemit-web-app-part-10-retrieving-comments-with-getcontentreplies/data):

```javascript
{
    "tags": [
        "steemdev",
        "developer",
        "javascript",
        "steemjs",
        "steem-dev"
    ],
    "links": [
        "\/@jfollas\/write-a-steemit-web-app-part-9-retrieving-content-with-getdiscussionsby",
        "https:\/\/esteem.ws\/"
    ],
    "image": [
        "https:\/\/steemitimages.com\/DQmZBbDGvKqM8V46NHaXoT7nZvrXhHLtTysrhixRu8eS87g\/javascriptlogo.png"
    ],
    "format": "markdown",
    "app": "steemit\/0.1"
}
```

<br/>Steemit uses the first entry from the `image` array as the blog's picture (you can even provide this in the metadata without actually having an image in the blog post). It also uses the `tags` array to set the various categories for the blog post (maximum of 5). 

I am not sure at this time if the remaining data is used by the Condenser (i.e., steemit.com) or other apps, but `format` seems to be either "markdown" or "html", depending on the content of the post body. `app` is an identifier for the application that is posting (i.e., your web app). And `links` is apparently an array of all of the URLs found in the body.

## Replies
For replies or comments, provide the actual author and permlink that you are replying to as the `parent_author` and `parent_permlink` (these will be properties of the content's data). 

There seems to be a convention for the structure of a reply's own permlink (slug). For example:

`re-jfollas-write-a-steemit-web-app-part-10-retrieving-comments-with-getcontentreplies-20170802t041610122z`

Fortunately, Steem.js provides a helper function to create a proper `permlink` for you given the `parent_author` and `parent_permlink`:

```javascript
const permlink = steem.formatter.commentPermlink(parent_author, parent_permlink)
```

<br>As for the `json_metadata`, there doesn't seem to be a lot of consistency between apps. Steemit.com will submit something like this:

```javascript
{
    "tags": [
        "steemdev"
    ],
    "users": [
        "jfollas"
    ],
    "app": "steemit\/0.1"
}
```

<br/>The `tags` array will contain the main post's primary tag, as well as any `#tag` mentions found in the body. `users` will contain any `@user` mention found in the body. Steemit doesn't seem to use these yet, but I'm hopeful that there will be a database API developed later to allow you to find `@user` mentions (so maybe including them in the metadata is just the first step in that process).

# Deleting Content
Now, the Steemit.com website doesn't permit a post or comment to be deleted. But, there is an API function that allows for this, if ever needed. Note that this will not remove record of the post or comment from the blockchain itself, because that is a permanent recording of all transactions. But, it will prevent the content from appearing on Steemit.com, at least.

```javascript
steem.broadcast.deleteComment(private_posting_wif, author, permlink)
```

<br/>The caveat here, though, is that the post cannot have any children (replies). Once it does, calling `deleteComment()` will result in an error.


![javascriptlogo.png](https://steemitimages.com/DQmZBbDGvKqM8V46NHaXoT7nZvrXhHLtTysrhixRu8eS87g/javascriptlogo.png)

_(Next Post: [Part 12](/@jfollas/write-a-steemit-web-app-part-12-voting))_
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorjfollas
permlinkwrite-a-steemit-web-app-part-11-posting-content
categorysteemdev
json_metadata{"tags":["steemdev","developer","javascript","steemjs","steem-dev"],"image":["https://steemitimages.com/DQmZBbDGvKqM8V46NHaXoT7nZvrXhHLtTysrhixRu8eS87g/javascriptlogo.png"],"links":["/@jfollas/write-a-steemit-web-app-part-10-retrieving-comments-with-getcontentreplies","https://steemdb.com/steemdev/@jfollas/write-a-steemit-web-app-part-10-retrieving-comments-with-getcontentreplies/data","/@jfollas/write-a-steemit-web-app-part-12-voting"],"app":"steemit/0.1","format":"markdown"}
created2017-08-08 03:15:06
last_update2017-08-13 22:30:24
depth0
children14
last_payout2017-08-15 03:15:06
cashout_time1969-12-31 23:59:59
total_payout_value58.772 HBD
curator_payout_value19.159 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,153
author_reputation4,351,701,088,490
root_title"Write a Steemit Web App: Part 11 - Posting Content"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id11,126,092
net_rshares21,106,616,116,414
author_curate_reward""
vote details (36)
@dan.sanchez ·
I'm having a bit of trouble posting an image....  I  was finally able to get a seeminly acceptable JSON response when posting content with an image... I am able to successfully post content, but no image appears. Can you tell me what I am doing wrong:

Posting Code:
this.submit = function() {
		var tester3 = "";
		var tester2 = 'test-title';
		var jsontext = '["image","https:\/\/steemitimages.com\/DQmZBbDGvKqM8V46NHaXoT7nZvrXhHLtTysrhixRu8eS87g\/javascriptlogo.png"]';
		var tagger = JSON.parse(jsontext);
		
      var permlink = 're-' + tester2 + '-' + Math.floor(Date.now() / 1000);
	  steemconnect.comment(tester3, tester2, $scope.username, permlink, '', $scope.comment, tagger, function(err, result) {
        console.log(err, result);
        $scope.comment = '';
        $scope.$apply();
        self.loadComments();
      });
    };




JSON Response:

{result: {…}}
result
:
block_num
:
14973208
expiration
:
"2017-08-28T15:15:21"
expired
:
false
extensions
:
[]
id
:
"9a31ab72972752636f296e8749dd654893832934"
operations
:
Array(1)
0
:
Array(2)
0
:
"comment"
1
:
author
:
"mytest-account123"
body
:
"test"
json_metadata
:
"["image","https://steemitimages.com/DQmZBbDGvKqM8V46NHaXoT7nZvrXhHLtTysrhixRu8eS87g/javascriptlogo.png"]"
parent_author
:
""
parent_permlink
:
"test-periscope"
permlink
:
"re-test-periscope-1503933261"
title
:
""
__proto__
:
Object
length
:
2
__proto__
:
Array(0)
length
:
1
__proto__
:
Array(0)
ref_block_num
:
30996
ref_block_prefix
:
3937866285
signatures
:
["1f7ba833192e1894814fb6d87d2ba478ef71d0eddd4a70d3cc…19e61602294408561746ee65eb44462f232745690c4e71d84"]
trx_num
:
5
__proto__
:
Object
__proto__
:
Object
properties (22)
authordan.sanchez
permlinkre-jfollas-write-a-steemit-web-app-part-11-posting-content-20170828t155134394z
categorysteemdev
json_metadata{"tags":["steemdev"],"image":["https://steemitimages.com/DQmZBbDGvKqM8V46NHaXoT7nZvrXhHLtTysrhixRu8eS87g/javascriptlogo.png"],"app":"steemit/0.1"}
created2017-08-28 15:51:33
last_update2017-08-28 15:51:33
depth1
children1
last_payout2017-09-04 15:51:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,651
author_reputation88,679,759
root_title"Write a Steemit Web App: Part 11 - Posting Content"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id13,136,815
net_rshares0
@dibya612 ·
@danSanchez I alsofacing same Problem, Would you help me to solve this?????????
properties (22)
authordibya612
permlinkre-dansanchez-re-jfollas-write-a-steemit-web-app-part-11-posting-content-20180319t091220906z
categorysteemdev
json_metadata{"tags":["steemdev"],"users":["dansanchez"],"app":"steemit/0.1"}
created2018-03-19 09:12:24
last_update2018-03-19 09:12:24
depth2
children0
last_payout2018-03-26 09:12:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length79
author_reputation274,700,675
root_title"Write a Steemit Web App: Part 11 - Posting Content"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id45,302,256
net_rshares0
@dan.sanchez ·
var jsontext = '["image","https:\/\/steemitimages.com\/DQmZBbDGvKqM8V46NHaXoT7nZvrXhHLtTysrhixRu8eS87g\/javascriptlogo.png"]';
properties (22)
authordan.sanchez
permlinkre-jfollas-write-a-steemit-web-app-part-11-posting-content-20170828t155343364z
categorysteemdev
json_metadata{"tags":["steemdev"],"image":["https://steemitimages.com/DQmZBbDGvKqM8V46NHaXoT7nZvrXhHLtTysrhixRu8eS87g/javascriptlogo.png"],"app":"steemit/0.1"}
created2017-08-28 15:53:42
last_update2017-08-28 15:53:42
depth1
children0
last_payout2017-09-04 15:53:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length126
author_reputation88,679,759
root_title"Write a Steemit Web App: Part 11 - Posting Content"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id13,137,022
net_rshares0
@dan.sanchez ·
var jsontext = '["image","https://steemitimages.com/DQmZBbDGvKqM8V46NHaXoT7nZvrXhHLtTysrhixRu8eS87g/javascriptlogo.png"]';

The / are actually \/
properties (22)
authordan.sanchez
permlinkre-jfollas-write-a-steemit-web-app-part-11-posting-content-20170828t155522691z
categorysteemdev
json_metadata{"tags":["steemdev"],"image":["https://steemitimages.com/DQmZBbDGvKqM8V46NHaXoT7nZvrXhHLtTysrhixRu8eS87g/javascriptlogo.png"],"app":"steemit/0.1"}
created2017-08-28 15:55:21
last_update2017-08-28 15:55:21
depth1
children0
last_payout2017-09-04 15:55:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length145
author_reputation88,679,759
root_title"Write a Steemit Web App: Part 11 - Posting Content"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id13,137,175
net_rshares0
@dibya612 ·
just asking how to add image in post using steemjs
properties (22)
authordibya612
permlinkre-jfollas-write-a-steemit-web-app-part-11-posting-content-20180319t090957810z
categorysteemdev
json_metadata{"tags":["steemdev"],"app":"steemit/0.1"}
created2018-03-19 09:10:00
last_update2018-03-19 09:10:00
depth1
children0
last_payout2018-03-26 09:10:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length50
author_reputation274,700,675
root_title"Write a Steemit Web App: Part 11 - Posting Content"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id45,301,921
net_rshares0
@dollface ·
Upvoted & RESTEEMED :]
properties (22)
authordollface
permlinkre-jfollas-write-a-steemit-web-app-part-11-posting-content-20170808t042439785z
categorysteemdev
json_metadata""
created2017-08-08 04:24:24
last_update2017-08-08 04:24:24
depth1
children0
last_payout2017-08-15 04:24:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length22
author_reputation18,242,282,557
root_title"Write a Steemit Web App: Part 11 - Posting Content"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id11,130,352
net_rshares0
@fish-tennis ·
1231231
properties (22)
authorfish-tennis
permlinkre-jfollas-write-a-steemit-web-app-part-11-posting-content-20180731t072719381z
categorysteemdev
json_metadata{"tags":["steemdev"],"app":"steemit/0.1"}
created2018-07-31 07:25:30
last_update2018-07-31 07:25:30
depth1
children0
last_payout2018-08-07 07:25:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length7
author_reputation656,535,039
root_title"Write a Steemit Web App: Part 11 - Posting Content"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id66,607,257
net_rshares0
@marcaprio ·
I am looking thru your posts and they are very interesting, writing steemit apps. I might be interested to play a bit myself with that at some point, who knows. I generally like coding, but not doing much of that at the moment. All props to you sir!
properties (22)
authormarcaprio
permlinkre-jfollas-write-a-steemit-web-app-part-11-posting-content-20170808t052317828z
categorysteemdev
json_metadata{"tags":["steemdev"],"app":"steemit/0.1"}
created2017-08-08 05:23:18
last_update2017-08-08 05:23:18
depth1
children0
last_payout2017-08-15 05:23:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length249
author_reputation154,421,522,586
root_title"Write a Steemit Web App: Part 11 - Posting Content"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id11,134,299
net_rshares0
@neuromancer ·
$0.07
Interesting, again. Of note:
> "...length of the slug must be between 1 and 255 characters..."

A byte, path depth, ? Hmm...
> "...provide this in the metadata without actually having an image in the blog post..."

Custom thumbnails, anyone?

> ..."format seems to be either "markdown" or "html", depending on the content..."

Interesting, but, I wonder; I've made posts with mixed markdown & html tag content, which is necessary if you wish to make use of `<div>`s, for example:

```html
### [useful resource](https://steemit.com/@neuromancer)
<div class=pull-right>https://steemitimages.com/DQmQMZPRjgWkSdhQZMYrmtm6PU9sS1HKSpVHzmjTXp9j2Se/noteymcnoteface.png</div> I will show you how to make some text that will wrap the noteymcnoteface.png image but also has <b>bold</b> and <i>italic</i> HMTL tagged text in it. <br> <br> In fact, I'm about to publish an article on it to help you all achieve advanced formatting for your work :]
```
<br>
Produces:
### [useful resource](https://steemit.com/@neuromancer)
<div class=pull-right>https://steemitimages.com/DQmQMZPRjgWkSdhQZMYrmtm6PU9sS1HKSpVHzmjTXp9j2Se/noteymcnoteface.png</div> I will show you how to make some text that will wrap the noteymcnoteface.png image but also has <b>bold</b> and <i>italic</i> HMTL tagged text in it. <br><br>  In fact, I'm about to publish an article on it to help you all achieve advanced formatting for your work :]
👍  
properties (23)
authorneuromancer
permlinkre-jfollas-write-a-steemit-web-app-part-11-posting-content-20170808t073458497z
categorysteemdev
json_metadata{"tags":["steemdev"],"image":["https://steemitimages.com/DQmQMZPRjgWkSdhQZMYrmtm6PU9sS1HKSpVHzmjTXp9j2Se/noteymcnoteface.png"],"links":["https://steemit.com/@neuromancer"],"app":"steemit/0.1"}
created2017-08-08 07:35:00
last_update2017-08-08 07:35:00
depth1
children2
last_payout2017-08-15 07:35:00
cashout_time1969-12-31 23:59:59
total_payout_value0.054 HBD
curator_payout_value0.018 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,399
author_reputation865,641,939,516
root_title"Write a Steemit Web App: Part 11 - Posting Content"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id11,143,258
net_rshares19,804,952,623
author_curate_reward""
vote details (1)
@jfollas · (edited)
Again, I'm not sure how much Steemit (or other apps) actually depend on the `format` metadata value, so you may get the same results with no format specified at all (because it looks like they preserve sanitized html within markdown when it renders).  I noticed after I posted that eSteem provides "markdown+html" as the `format` value in its posts.

But, because each app renders markdown differently, I would be concerned that doing anything really fancy would result in a post that looks bad when rendered on different apps. eSteem, for instance, does a bad job rendering markdown code blocks (and I'm not even a fan of how Steemit renders code - my own app will use [Prism.js](http://prismjs.com/) to enhance the styling of code blocks).
👍  
properties (23)
authorjfollas
permlinkre-neuromancer-re-jfollas-write-a-steemit-web-app-part-11-posting-content-20170808t131825016z
categorysteemdev
json_metadata{"tags":["steemdev"],"app":"steemit/0.1","links":["http://prismjs.com/"]}
created2017-08-08 13:18:21
last_update2017-08-08 13:22:54
depth2
children1
last_payout2017-08-15 13:18:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length741
author_reputation4,351,701,088,490
root_title"Write a Steemit Web App: Part 11 - Posting Content"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id11,169,505
net_rshares227,903,597
author_curate_reward""
vote details (1)
@neuromancer ·
There really needs to be a canonical approach if they want authors to put any effort into formatting their articles. Somewhere over the rainbow. 

Thanks for your efforts investigating and clarifying, I think the inspection and insight will prove useful to devs and may result in further consideration (provided someone's watching this).
properties (22)
authorneuromancer
permlinkre-jfollas-re-neuromancer-re-jfollas-write-a-steemit-web-app-part-11-posting-content-20170808t133623062z
categorysteemdev
json_metadata{"tags":["steemdev"],"app":"steemit/0.1"}
created2017-08-08 13:36:27
last_update2017-08-08 13:36:27
depth3
children0
last_payout2017-08-15 13:36:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length337
author_reputation865,641,939,516
root_title"Write a Steemit Web App: Part 11 - Posting Content"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id11,171,160
net_rshares0
@oyvindsabo ·
Thanks! I'm super grateful for this tutorial. I have literally found no other documentation about how to write replies, using Steem.js. This one worked like a charm!
properties (22)
authoroyvindsabo
permlinkre-jfollas-write-a-steemit-web-app-part-11-posting-content-20180318t003843883z
categorysteemdev
json_metadata{"tags":["steemdev"],"app":"steemit/0.1"}
created2018-03-18 00:38:45
last_update2018-03-18 00:38:45
depth1
children0
last_payout2018-03-25 00:38:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length165
author_reputation1,341,628,885,463
root_title"Write a Steemit Web App: Part 11 - Posting Content"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id45,047,055
net_rshares0
@quangle ·
Dear jfollas,

That's very helpful API

There are some points that I don't get it:
1. I did use this API to delete a comment and it works well if you create a post and delete it a few seconds later. However, it seems it doesn't work with a post which is created couple of hours ago.
2. I did search and know that we can delete a post/comment if they don't have any replies/votes and must be less than 7 days

My case fulfiled all these conditions, but API is always return this error " comment.cashout_time != fc::time_point_sec::maximum()"

You can take a look at this link
https://github.com/EOSIO/logchain/blob/master/libraries/chain/steem_evaluator.cpp#L378

Thank you so much for any feedback

Regards
properties (22)
authorquangle
permlinkre-jfollas-write-a-steemit-web-app-part-11-posting-content-20181021t060654816z
categorysteemdev
json_metadata{"tags":["steemdev"],"links":["https://github.com/EOSIO/logchain/blob/master/libraries/chain/steem_evaluator.cpp#L378"],"app":"steemit/0.1"}
created2018-10-21 05:59:45
last_update2018-10-21 05:59:45
depth1
children0
last_payout2018-10-28 05:59:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length706
author_reputation243,742,722
root_title"Write a Steemit Web App: Part 11 - Posting Content"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id73,730,865
net_rshares0
@stoodkev ·
This is a test!
👍  
properties (23)
authorstoodkev
permlinkre-jfollas-write-a-steemit-web-app-part-11-posting-content-20171002t144804171z
categorysteemdev
json_metadata{"tags":["test"],"app":"steemjs/examples"}
created2017-10-02 14:48:06
last_update2017-10-02 14:48:06
depth1
children0
last_payout2017-10-09 14:48:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length15
author_reputation190,283,772,273,558
root_title"Write a Steemit Web App: Part 11 - Posting Content"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id16,575,041
net_rshares5,313,444,725
author_curate_reward""
vote details (1)