The official SteemConnect JavaScript SDK.
To install and run SteemConnect.js, follow this quick start guide
SteemConnect.js was designed to work both in the browser and in Node.js.
To install SteemConnect.js on Node.js, open your terminal and run:
npm i steemconnect --save
You can create an index.html file and include SteemConnect.js with:
<script src="https://cdn.jsdelivr.net/npm/steemconnect"></script>
For general information about SteemConnect and setting up your app you can checkout the developer documentation.
Call the Client() method when your app first loads to init the SDK:
var steemconnect = require('steemconnect');
var client = new steemconnect.Client({
app: 'staging.app',
callbackURL: 'https://demo.steemconnect.com',
scope: ['vote', 'comment']
});
Parameters:
This method trigger SteemConnect Chrome extension or Steem Keychain for log in, if user don't have Chrome extension enabled it will fallback to SteemConnect website.
var params = {};
// The "username" parameter is required prior to log in for "Steem Keychain" users.
if (steemconnect.useSteemKeychain) {
params = { username: 'fabien' };
}
client.login(params, function(err, token) {
console.log(err, token)
});
The following method returns a URL that you can redirect the user to so that they may log in to your app through SteemConnect:
var link = client.getLoginURL(state);
// => https://steemconnect.com/oauth2/authorize?client_id=[app]&redirect_uri=[callbackURL]&scope=vote,comment&state=[state]
Parameters:
After logging in, SteemConnect will redirect the user to the "redirect_uri" specified in the login url above and add the following query string parameters for your app to use:
Once a user is logged in to your app you can call the following method to get the details of their account:
client.me(function (err, res) {
console.log(err, res)
});
If it is successful, the result will be a JSON object with the following properties:
{
account: { id: 338059, name: "yabapmatt", ...},
name: "yabapmatt",
scope: ["vote"],
user: "yabapmatt",
_id: "yabapmatt"
}
The revokeToken() method will log the current user out of your application by revoking the access token provided to your app for that user:
client.revokeToken(function (err, res) {
console.log(err, res)
});
The vote() method will cast a vote on the specified post or comment from the current user:
client.vote(voter, author, permlink, weight, function (err, res) {
console.log(err, res)
});
Parameters:
The comment() method will post a comment on an existing post or comment from the current user:
client.comment(parentAuthor, parentPermlink, author, permlink, title, body, jsonMetadata, function (err, res) {
console.log(err, res)
});
The comment() method is rate limited to 5 minutes per root comment (post), and 20 seconds per non-root comment (reply).
The deleteComment() method will mark a comment as deleted.
client.deleteComment(author, permlink, function (err, res) {
console.log(err, res)
})
client.customJson(requiredAuths, requiredPostingAuths, id, json, function (err, res) {
console.log(err, res)
});
client.reblog(account, author, permlink, function (err, res) {
console.log(err, res)
});
client.follow(follower, following, function (err, res) {
console.log(err, res)
});
client.unfollow(unfollower, unfollowing, function (err, res) {
console.log(err, res)
});
client.ignore(follower, following, function (err, res) {
console.log(err, res)
});
client.claimRewardBalance(account, rewardSteem, rewardSbd, rewardVests, function (err, res) {
console.log(err, res)
});
const op = ['transfer', {
from: '__signer',
to: 'fabien',
amount: '0.001 STEEM'
}];
steemconnect.sendOperation(op, {}, function(err, result) {
console.log(err, result);
});