Converting SBD to STEEM | An automated process in Node.js

in #stem3 years ago


As we all know, when we author a post we can choose between a 50% SBD and 50% STEEM or 100% Steem Power payout. Most of the time I choose the 50/50 option because I want to have some liquid STEEM to use wherever I see fit. I have less of a use for SBD (except for the occasional post promotion to @tipu or @qustodian) and I often end up having to submit a convert request to STEEM. Each conversion request takes 3.5 days.

Because I'm a geek, I decided to automate this process—it's actually quite simple! You'll need a Node.js environment and the steem-js library for this.

As I have several Steem accounts, I grant posting/active authority to a master account so I only have to have one set of keys in my script. You can use my simple webpage to do this for any account. All actions on this page use Steem Keychain, so no passwords are required for input.


Here's the script:

#! /usr/bin/env node

var username = process.argv[2];
if( process.argv.length != 3 )
  console.log( "Usage: %s <username>", process.argv[1] );
  process.exit( 1 );

const Steem = require( 'Steem' );
const activeKey = '5xxxxxxx';  // replace with your active key

Steem.api.getAccounts( [username], convertRequest );

function convertRequest( err, result )
  if( err )
    console.log( err, result );

  var account;
  try {
    account = result[0];
    if( parseFloat( account.sbd_balance ) <= 0 )
      process.exit( 0 );
  } catch( ex ) {
    console.log( `No data for ${username}` );
    process.exit( 1 );

  var message = `${} convert request: ${account.sbd_balance}`;
  console.log( message );
    Math.floor(Math.random() * 10000000),
    function( err, result )
      console.log( err, result );

Usage: ./convert-request.js contrabourdon

This is what happens, step-by-step:

  1. Check that a username is entered as an argument
  2. Get the Steem account information for the user, pass details to convertRequest( )
  3. Exit if there is a 0.00 SBD balance
  4. Broadcast a convert request for the SBD balance

After 3.5 days, this will be converted to STEEM and appear in your wallet.

I am scheduling this to run daily via cron:

0 0 * * * /home/ec2-user/convert-request.js contrabourdon

I hope this is useful to you as it is for me :)
...@contrabourdon is now off to the Bahamas!

Consider using one of your witness votes on untersatz!

Run by myself and organduo—supporting the community with regular contests: Easy SBI Contest, Pinky and Spiky Drawing Contest and Secrets of Organ Playing Contest. Also powering the popular giphy bot and donating STEEM for deemarshall's creative contests.

You can also support me using Steem Basic Income


@partitura You might like this one.

You got a 11.54% upvote from @ocdb courtesy of @contrabourdon! :)

@ocdb is a non-profit bidbot for whitelisted Steemians, current min bid is 2 SBD and max bid is 12 SBD and the equivalent amount in STEEM.
Check our website for the whitelist, queue and delegation info. Join our Discord channel for more information.

If you like what @ocd does, consider voting for ocd-witness through SteemConnect or on the Steemit Witnesses page. :)