4th Street Bar Hive-Bar

Hive-Bar Powered by Hive beta-fdb5b5b

Community post

Steemit Post Comment Using Nodejs Bot Tutorial

https://steemit.com/images/steemit.png

In this tutorial, you will learn to use steemjs to post a comment to steemit.com.

Prerequisites

Basic knowledge in nodejs.

The data is fetched as JSON from URL and then it is sent to the steemit. We will be using the following dependencies

  • Steem
  • HTTP

You can install these by the following command

  • npm install steem --save
  • npm install http --save
  • First, we need to create two variable for steem and http

    var steem = require('steem');
    var http = require('http');

    Next, We will create a server and listen to a port. You can use any other port.

    http.createServer(function (req, res) {
    }).listen(2001); 

    The next part is to fetch the data that we want to post. You need to add your username, posting key from steemit(Wallet -> Permission->Show Private Key)

    http.get('http://yourwebsite.com/api/steemit.json',function(res){
    var body = '';
    res.on('data',function(chunk){
    body += chunk;
    });
    res.on('end',function(){
    var post = JSON.parse(body);
    steem.broadcast.comment(
    'POSTING_PRIVATE_KEY', // your steemit posting private key
    '',
    post.category,
    'YOUR_STEEMIT_USERNAME', // your username
    post.slug, // Your Steemit post slug
    post.title,
    post.message,
    { tags: [ post.tags ] },
    function(err, result) {
    console.log(err, result);
    $('#message').text(err);
    $('#ms').text(result.id);
    });
    })
    }); 

    Example of JSON file that we fetch from URL

    {
    title: "Your Post Title",
    message: "Your message contents goes here. You can add image url too.",
    tag: ""general" ",
    category: "programming",
    slug: "your-post-title"
    }
    

    Full Source Code

    After uploading the file to your server you need to run node file.js or forever start file.js

    var steem = require('steem');
    var http = require('http'); 
    
    http.createServer(function (req, res) {
     
    http.get('http://yourwebsite.com/api/steemit.json',function(res){
      var body = '';
    
      res.on('data',function(chunk){
        body += chunk;
      });
    
      res.on('end',function(){
         var post = JSON.parse(body);
        steem.broadcast.comment(
          'POSTING_PRIVATE_KEY', // your steemit posting private key 
          '',  
          post.category,  
          'YOUR_STEEMIT_USERNAME', // your username
          post.slug, // Your Steemit post slug
          post.title, 
          post.message, 
          { tags: [ post.tags ] },  
          function(err, result) {
            console.log(err, result);
            $('#message').text(err); 
            $('#ms').text(result.id);
        });
        
      })
    
    });
    res.end('Processing\n');
    
    }).listen(2001);
    3 upvotes $0.00

    Replies (2)

    Review before signing

    Posting as . Signing with . Keychain permission: Posting. Hive Keychain will ask you to approve this action next.

    
      
    Technical details

    Operation fingerprint: