steemconnect-od

SteemConnect JavaScript SDK

Usage no npm install needed!

<script type="module">
  import steemconnectOd from 'https://cdn.skypack.dev/steemconnect-od';
</script>

README

npm CircleCI GitHub license

SteemConnect.js

SteemConnect JavaScript SDK. This version only supports the login scope!!!

Getting started

To install and run SteemConnect.js, follow this quick start guide

Install

To install SteemConnect.js on Node.js, open your terminal and run:

npm i steemconnect-od --save

Usage

For general information about SteemConnect V2 and setting up your app you can follow these guides:

SDK Methods

Init SDK

Call the Initialize() method when your app first loads to initialize the SDK:

var sc2 = require('steemconnect-od');

var api = sc2.Initialize({
  masterAccount: 'oracle-d',
  masterAccountWif: '5esdf',
  authURL: `http://localhost:8000/auth`,
  app: 'busy',
  callbackURL: 'http://localhost:8000/demo/',
  accessToken: 'access_token'
});

Parameters:

  • masterAccount: This is the account that will broadcast all operations
  • masterAccountWif: This is the private WIF of the master account
  • authURL: This is the redirect url for the posting auth request
  • app: This is the name of the app that was registered in the SteemConnect V2 dashboard
  • callbackURL: This is the URL that users will be redirected to after interacting with SC2. It must be listed in the "Redirect URI(s)" list in the app settings EXACTLY the same as it is specified here
  • accessToken: If you have an oauth2 access token for this user already you can specify it here, otherwise you can leave it and set it later using sc2.setAccessToken(accessToken).
  • scope: This is a list of operations the app will be able to access on the user's account. For a complete list of scopes see: https://github.com/steemit/steemconnect/wiki/OAuth-2#scopes

Get Login URL

The following method returns a URL that you can redirect the user to so that they may log in to your app through SC2:

var link = api.getLoginURL(state);
console.log(link)
// => https://steemconnect.com/oauth2/authorize?client_id=[app]&redirect_uri=[callbackURL]&scope=vote,comment&state=[state]

Parameters:

  • state: Data that will be passed to the callbackURL for your app after the user has logged in.

After logging in, SC2 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:

  • access_token: This is the oauth2 access token that is required to make any Steem API calls on behalf of the current user. Once you have this you need to tell the SC2 SDK to use it by either specifying it as a parameter to the init() method call or by calling sc2.setAccessToken([accessToken]).
  • expires_in: The number of seconds until the access token expires.
  • username: The username of the current user.

Get user profile

Once a user is logged in to your app you can call the following method to get the details of their account:

api.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",
  user_metadata: {},
  _id: "yabapmatt"
}

Verify that the master account has access to the current user

let role = 'posting';
api.verifyAccess(role).then(access => {
  if (access === false) {
    // master account has no access
  } else {
    // master account has access
  }
})

Vote

The vote() method will cast a vote on the specified post or comment from the current user:

api.vote(voter, author, permlink, weight, function (err, res) {
  console.log(err, res)
});

Parameters:

  • voter: The Steem username of the current user.
  • author: The Steem username of the author of the post or comment.
  • permlink: The link to the post or comment on which to vote. This is the portion of the URL after the last "/". For example the "permlink" for this post: https://steemit.com/steem/@ned/announcing-smart-media-tokens-smts would be "announcing-smart-media-tokens-smts".
  • weight: The weight of the vote. 10000 equale a 100% vote.
  • callback: A function that is called once the vote is submitted and included in a block. If successful the "res" variable will be a JSON object containing the details of the block and the vote operation.

Comment

The comment() method will post a comment on an existing post or comment from the current user:

api.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).

Delete Comment

The deleteComment() method will mark a comment as deleted.

api.deleteComment(author, permlink, function (err, res) {
  console.log(err, res)
})

Generate hot signing link

The sign() method creates a URL to which your app can redirect the user to perform a signed transaction on the blockchain such as a transfer or delegation:

var link = api.sign('transfer', {
  to: 'fabien',
  amount: '1.000 STEEM',
  memo: 'Hello World!',
}, 'http://localhost:8000/demo/transfer-complete');

console.log(link);
// => https://steemconnect.com/sign/transfer?to=fabien&amount=1.000%20STEEM&memo=Hello%20World!&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fdemo%2Ftransfer-complete

Logout

The revokeToken() method will log the current user out of your application by revoking the access token provided to your app for that user:

api.revokeToken(function (err, res) {
  console.log(err, res)
});

This will not revoke the access the master account has to the users account

Reblog

api.reblog(account, author, permlink, function (err, res) {
  console.log(err, res)
});

Follow

api.follow(follower, following, function (err, res) {
  console.log(err, res)
});

Unfollow

api.unfollow(unfollower, unfollowing, function (err, res) {
  console.log(err, res)
});

Ignore

api.ignore(follower, following, function (err, res) {
  console.log(err, res)
});

Claim Reward Balance

api.claimRewardBalance(account, rewardSteem, rewardSbd, rewardVests, function (err, res) {
  console.log(err, res)
});

Update User Metadata

api.updateUserMetadata(metadata, function (err, res) {
  console.log(err, res)
});

Changelog

2.1.0

  • Fork from main repository

2.0.0

  • Update to Webpack 4, fix import issue #50

1.0.2

  • Deprecate v2.steemconnect.com endpoint

1.0.1

  • Fixed response error checking.

1.0.0

  • Migrated to instance based architecture. You have to create new instance using Initialize function now. See documentation above.