dev tutorial - Using steemconnect with async/await

in #steemdev6 years ago

So recently I started using steemconnect instead of asking for posting keys. My webserver doesn like waiting around for the response from steemconnect callback so I decided to try out using bluebird for promisification.

Thought I would just drop a short snippet of code for anyone drying to do the same.

var Promise = require('bluebird');
const sc2 = require('sc2-sdk');

// init steemconnect
let api = sc2.Initialize({
    app: 'yourappname',
    callbackURL: config.get('steemconnect_callback_url'),
    accessToken: 'access_token',
    scope: ['vote', 'comment', 'comment_options'],
});

Promise.promisifyAll(api);

once that is set up you can now use it with async/await.

const retVal = await api.voteAsync(ctx.session.user.steem_username, author, permlink, weight);

I really hate callbacks so this just makes me feel good. Make sure to note the method namechange. You no longer call the vote() method but you now call the voteAsync() method that bluebird created for you. The original method remains unchanged and would fail if you tried to call it using await and not passing a callback.

Sort:  

test reply for replying to

replying to my reply, hopefully

test 1 2 3