Steem.Js for dummies #6: Broadcasting several operations
In this example, we will try the broadcast.send function to perform two simultaneous operations : post a comment (actually it's a post, not a comment, but it is regarded as the same), and comment_options to set beneficiaries.
I will take a top-down approach this time and will give you the relevant code from my beneficiaries code on @steem-plus:
var operations = [
['comment',
{
parent_author: '',
parent_permlink: tags[0],
author: author,
permlink: permlink,
title: title,
body: body,
json_metadata : JSON.stringify({
tags: tags,
app: 'steemplus'
})
}
],
['comment_options', {
author: author,
permlink: permlink,
max_accepted_payout: '100000.000 SBD',
percent_steem_dollars: sbdpercent,
allow_votes: true,
allow_curation_rewards: true,
extensions: [
[0, {
beneficiaries: beneficiaries
}]
]
}]
];
steem.broadcast.send(
{ operations: operations, extensions: [] },
{ posting: wif },
function(e, r) {
//TODO : Do something here
});
Now, let's break it into pieces. Ready?
As you can see in the code, we will broadcast two operations:
Comment
In the first object of our array of operations, you will need to fill the following parameters:
'comment',
{
parent_author: '',
parent_permlink: tags[0],
author: author,
permlink: permlink,
title: title,
body: body,
json_metadata : JSON.stringify({
tags: tags,
app: 'steemplus'
})
}
parent_author: Who authored the post or comment you are replying to? Here we are not posting a comment but a blog, this field is thusnullparent_permlink: Permlink of the parent if you are sending a comment, for an original blog, it corresponds to the first tag.author: really, you're going to make me write this? Put the name of the author there =ppermlink: create the permlink from the title and put it in here, be careful, no space allowed.titleandbody: well...json_metadatais an object containing additional information on the operation. Here, I ve only put the tags and the name of the app broadcasting.
You could broadcast this comment already, but let's make it better and associate it with the second operation:
CommentOptions
Here is what it looks like:
comment_options', {
author: author,
permlink: permlink,
max_accepted_payout: '100000.000 SBD',
percent_steem_dollars: sbdpercent,
allow_votes: true,
allow_curation_rewards: true,
extensions: [
[0, {
beneficiaries: beneficiaries
}]
]
}
In this part of the we have to redundant variables : author and permlink, so just input the same in here.
As for the rest:
max_accepted_payoutis self-explanatory, put something big unless you want to decline part of the rewardspercent_steem: 10000 (100.00%) means 50/50 SBD/SP post, 0 means 100% SP post.allow_votes: people can vote on your post, wouldn't really make sense to put false, right?allow_curation_rewards: allow voters to get curation rewardsbeneficiariesare under extensions. To create the object, follow my lead:
beneficiaries.push({
account: 'steem-plus',
weight: 100*STEEM_PLUS_FEED
});
If STEEM_PLUS_FEED=5;, we will have a weight of 500 (5.00%). If that is the only beneficiary, by default, the author account will get the remaining 95% of the rewards. It has to be noted that all beneficiaries rewards are fully paid in SP regardless of percent_steem.
Finally send the broadcast
Now that everything is ready, you just need to send the broadcast:
steem.broadcast.send(
{ operations: operations, extensions: [] },
{ posting: wif },
function(e, r) {
//TODO : Do something here
});
The only thing you need to do here is adding the PRIVATE posting WIF. Now, it should work ;)
Hope this helps!
Posted on Utopian.io - Rewarding Open Source Contributors

Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Congratulations @stoodkev! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOPThank you for helping aspiring steemdevs get started with ease!...
Hey @stoodkev I am @utopian-io. I have just upvoted you at 7% Power!
Achievements
Suggestions
Human Curation
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x