A few days ago I wrote about the problems of the steem development ecosystem and notably the lack of examples/documentation on how to do things in this article.
It thought about how I could solve these problems and after a few days, and talking with @scipio about it, I created steemsnippets.
Steemsnippets
Steemsnippets is a github repository with small snippets of code(aka very small functions for some specific use cases) To interact with steem.
To give you an idea for now the repository contains those snippets :
- How to use the @almost-digital's testnet : https://testnet.steem.vc/
- How to create an account
- How to test if an username/password or username/privatekey is correct
All of them using steemjs but I plan to expand it to other languages very soon.
Disclamer : I use pieces of code that worked for me but there may be ways to improve them, if you do find some ways to do that, don't hesitate to submit a pull request :)
What's the point ?
The core idea behind this is to ease the pain and googling of the future programmers. On steemsnippets they can find ready to use functions that they can add in their workflow. Which means less time searching and more time creating awesome applications around steem.
How to contribute
I obviously accept external pull requests. Look up github's documentation on How to create a pull request on how to do so. But make sure you follow these rules :
- The function must be small and must only do one action (post an article, broadcast a vote etc).
- The function must be fully commented jsdoc/python docstring style
- The files must follow the directory structure :
- /library/nameofthesnippet/nameofhtesnippet.js/.py
- The file must include an installation file with all the dependencies. Aka a requirements.txt for python or a package.json for nodejs. This must be placed next to the source code file.
Don't forget that your contributions can be submitted to utopian.io for a reward so don't forget to look there as well :)
Example : Test if a login/password is correct
This snippet can be found here
/**
* Tests if an username/password pair is correct
* @param {String} username - username of the account
* @param {String} password - password of the account
* @return {boolean} valid - True of the password is correct, false if not (or if the account doesn't exists)
*/
function login_using_password(username, password) {
// Get the private posting key
var wif = steem.auth.toWif(username, password, 'posting');
steem.api.getAccounts([username], function (err, result) {
// check if the account exists
if (result.length !== 0) {
// get the public posting key
var pubWif = result[0].posting.key_auths[0][0];
var valid = false;
try {
// Check if the private key matches the public one.
valid = steem.auth.wifIsValid(wif, pubWif)
} catch (e) {
}
return valid;
}
return false;
});
}