├── .gitignore ├── LICENSE ├── README.md ├── dsteem ├── block_feed │ ├── block_feed.js │ └── package.json ├── claim_account │ ├── claim_account.js │ └── package.json ├── comment │ ├── comment.js │ └── package.json ├── create_discounted_account │ ├── create_discounted_account.js │ └── package.json ├── getContent │ ├── getContent.js │ └── package.json ├── get_active_votes │ ├── get_active_votes.js │ └── package.json ├── get_all_comments │ ├── get_all_comments.js │ ├── package.json │ └── utils.js ├── get_downvoting_power │ ├── get_downvoting_power.js │ └── package.json ├── post │ ├── package.json │ └── post.js ├── power_up │ ├── package.json │ └── power_up.js └── vote │ ├── package.json │ └── vote.js ├── steem-python ├── get_biggest_followers │ ├── get_biggest_followers.py │ └── requirements.txt ├── post │ ├── post.py │ └── requirements.txt └── vote │ ├── requirements.txt │ └── vote.py ├── steemconnect └── check_token │ ├── check_token.js │ └── package.json └── steemjs ├── account_update2 ├── account_update2.js ├── package-lock.json └── package.json ├── comment ├── comment.js └── package.json ├── create_account ├── create_account.js └── package.json ├── downvoting_power ├── downvoting_power.js └── package.json ├── get_active_votes ├── get_active_votes.js └── package.json ├── get_all_comments ├── get_all_comments.js └── package.json ├── get_followers_following ├── get_followers_following.js └── package.json ├── get_new_posts ├── get_new_posts.js └── package.json ├── get_reputation ├── get_reputation.js └── package.json ├── get_root_post ├── get_root_post.js └── package.json ├── get_steem_power ├── get_steem_power.js └── package.json ├── post ├── package.json └── post.js ├── post_exists ├── package-lock.json ├── package.json └── post_exists.js ├── power_up ├── package.json └── power_up.js ├── resteem ├── package.json └── resteem.js ├── simplified_rep_to_raw └── simplified_rep_to_raw.js ├── test_login ├── package.json └── test_login.js ├── transfer ├── package.json └── transfer.js ├── use_testnet ├── package.json └── use_testnet.js ├── vote ├── package.json └── vote.js └── voting_power ├── package.json └── voting_power.js /.gitignore: -------------------------------------------------------------------------------- 1 | dsteem/test_things/* 2 | steemjs/get_worth/* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Martin Lees 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Steemsnippets 2 | 3 | This is a collection of various snippets for steem. 4 | 5 | This is intended to be a collection where people can come, search for a specific functionality and have a working code snippet associated. 6 | 7 | If you try a snippet and it ends up not working/is outdated, please open an issue or a pull request :) 8 | 9 | Don't hesitate to submit a pull request if you want to contribute to the collection. 10 | 11 | Made by @howo : https://steemit.com/@howo 12 | 13 | 14 | # Current snippets : 15 | 16 | ## [Steem-js](https://github.com/steemit/steem-js) 17 | 18 | Active snippets (add things to the blockchain) 19 | - [How to use @almost-digital's testnet](https://github.com/drov0/steemsnippets/tree/master/steemjs/use_testnet) https://testnet.steem.vc/ 20 | - [How to create an account](https://github.com/drov0/steemsnippets/tree/master/steemjs/create_account) 21 | - [How to post an article](https://github.com/drov0/steemsnippets/tree/master/steemjs/post) 22 | - [How to comment on an article](https://github.com/drov0/steemsnippets/tree/master/steemjs/comment) 23 | - [How to cast a vote/flag](https://github.com/drov0/steemsnippets/tree/master/steemjs/vote) 24 | - [How to transfer steem/sbd](https://github.com/drov0/steemsnippets/tree/master/steemjs/transfer) 25 | - [How to resteem a post](https://github.com/drov0/steemsnippets/tree/master/steemjs/resteem) 26 | - [How to power up steem](https://github.com/drov0/steemsnippets/tree/master/steemjs/power_up) 27 | 28 | Passive snippets (read from the blockchain) : 29 | - [How to test if an username/password or username/privatekey is correct](https://github.com/drov0/steemsnippets/tree/master/steemjs/test_login) 30 | - [How to get recent posts](https://github.com/drov0/steemsnippets/tree/master/steemjs/get_new_posts) 31 | - [How to get the steem power of an user](https://github.com/drov0/steemsnippets/tree/master/steemjs/get_steem_power) 32 | - [How to get the number of followers and follows of an user](https://github.com/drov0/steemsnippets/tree/master/steemjs/get_followers_following) 33 | - [How to test if a post exists or not](https://github.com/drov0/steemsnippets/tree/master/steemjs/post_exists) 34 | - [How to get the voting power of an user ](https://github.com/drov0/steemsnippets/tree/master/steemjs/voting_power) 35 | - [How to get the downvoting power of an user ](https://github.com/drov0/steemsnippets/tree/master/steemjs/downvoting_power) 36 | - [Convert simplified reputation to an approximate raw score](https://github.com/drov0/steemsnippets/tree/master/steemjs/simplified_rep_to_raw) 37 | - [How to get the main post author and permlink from a comment](https://github.com/drov0/steemsnippets/tree/master/steemjs/get_root_post) 38 | - [How to get the simplified and raw reputation of an user](https://github.com/drov0/steemsnippets/tree/master/steemjs/get_reputation) 39 | 40 | ## [Dsteem](https://github.com/jnordberg/dsteem) 41 | 42 | - [How to post an article](https://github.com/drov0/steemsnippets/tree/master/dsteem/post) 43 | - [How to claim a discounted account](https://github.com/drov0/steemsnippets/tree/master/dsteem/claimAccount) 44 | - [How to comment on an article](https://github.com/drov0/steemsnippets/tree/master/dsteem/comment) 45 | - [How to cast a vote/flag](https://github.com/drov0/steemsnippets/tree/master/dsteem/vote) 46 | - [block stream skeleton to easily act on various operations as they go live on the blockchain](https://github.com/drov0/steemsnippets/tree/master/dsteem/block_feed) 47 | - [How to claim discounted accounts](https://github.com/drov0/steemsnippets/tree/master/dsteem/claim_account) 48 | - [How to create a discounted account](https://github.com/drov0/steemsnippets/tree/master/dsteem/create_discounted_account) 49 | - [How to get all the comments from a post in a tree structure](https://github.com/drov0/steemsnippets/tree/master/dsteem/get_all_comments) 50 | - [How to get active votes of an user](https://github.com/drov0/steemsnippets/tree/master/dsteem/get_active_votes) 51 | - [How to power up steem](https://github.com/drov0/steemsnippets/tree/master/dsteem/power_up) 52 | - [How to get the downvoting power of an user ](https://github.com/drov0/steemsnippets/tree/master/dsteem/get_downvoting_power) 53 | 54 | ## [steem-python](https://github.com/steemit/steem-python) 55 | 56 | - [How to post an article](https://github.com/drov0/steemsnippets/tree/master/steem-python/post) 57 | - [How to cast a vote/flag](https://github.com/drov0/steemsnippets/tree/master/steem-python/vote) 58 | 59 | 60 | 61 | # How to contribute 62 | 63 | I obviously accept external pull requests. Look up github's documentation on [How to create a pull request](https://help.github.com/articles/creating-a-pull-request/) on how to do so. But make sure you follow these rules : 64 | 65 | * The function must be small and must only do one action (post an article, broadcast a vote etc). 66 | * The function must be fully commented jsdoc/python docstring style 67 | * The files must follow the directory structure : 68 | * /library/nameofthesnippet/nameofhtesnippet.js/.py 69 | * 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. 70 | -------------------------------------------------------------------------------- /dsteem/block_feed/block_feed.js: -------------------------------------------------------------------------------- 1 | var dsteem = require('dsteem'); 2 | var es = require('event-stream') 3 | 4 | const steem = new dsteem.Client('https://rpc.buildteam.io');// We use buildteam's node as they are the fastest but feel free to use https://api.steemit.com 5 | 6 | /** 7 | * From a block number, gets it and parses the informations within it to store them on the blockchain 8 | * @param {int} blocknb - block number to parse. 9 | */ 10 | async function parseBlock(blocknb) { 11 | console.log(blocknb); 12 | const block = await steem.database.getBlock(blocknb); 13 | const tx = block['transactions']; 14 | 15 | for (let i = 0; i < tx.length; i++) { // iterate over each transaction 16 | for (let y = 0; y < tx[i]['operations'].length; y++) { // iterate over each operation of each transaction 17 | if (tx[i]['operations'][y][0] === "comment") { 18 | const post = tx[i]['operations'][y][1]; 19 | 20 | if (post['parent_author'] === "") // if the parent_author field is empty it's a post. 21 | { 22 | console.log(post); 23 | 24 | } else 25 | { 26 | // if parent_author is not empty then it's a comment 27 | console.log(post); 28 | } 29 | } 30 | else if (tx[i]['operations'][y][0] === "vote") { // Vote 31 | const vote = tx[i]['operations'][y][1]; 32 | 33 | console.log(vote); 34 | 35 | } 36 | else if (tx[i]['operations'][y][0] === "custom_json") { // Almost all the time used to perform follow/unfollow 37 | const custom_json = tx[i]['operations'][y][1]; 38 | 39 | if (custom_json['id'] === "follow") // Follow/unfollow 40 | { 41 | const follow_data = JSON.parse(custom_json['json']); 42 | console.log(follow_data); 43 | } else 44 | console.log(custom_json); // Something else. 45 | 46 | } 47 | else if (tx[i]['operations'][y][0] === "transfer") { // Transfer steem/sbd 48 | const transfer = tx[i]['operations'][y][1]; 49 | 50 | console.log(transfer); 51 | 52 | } else if (tx[i]['operations'][y][0] === "claim_reward_balance") { // Claim reward 53 | const claim_reward_balance = tx[i]['operations'][y][1]; 54 | 55 | console.log(claim_reward_balance); 56 | 57 | } else if (tx[i]['operations'][y][0] === "comment_options") { // Comments options, generally used to set beneficiaries. 58 | const comment_options = tx[i]['operations'][y][1]; 59 | 60 | console.log(comment_options); 61 | 62 | } else if (tx[i]['operations'][y][0] === "account_update") { // Update account infos (profile pic, description name etc). 63 | const account_update = tx[i]['operations'][y][1]; 64 | 65 | console.log(account_update); 66 | 67 | } else if (tx[i]['operations'][y][0] === "limit_order_cancel") { // Cancel marketplace order 68 | const limit_order_cancel = tx[i]['operations'][y][1]; 69 | 70 | console.log(limit_order_cancel); 71 | } else if (tx[i]['operations'][y][0] === "transfer_to_vesting") { // Power up 72 | const transfer_to_vesting = tx[i]['operations'][y][1]; 73 | 74 | console.log(transfer_to_vesting); 75 | } else if (tx[i]['operations'][y][0] === "transfer_to_savings") { // Put steem/sbd in savings 76 | const transfer_to_savings = tx[i]['operations'][y][1]; 77 | 78 | console.log(transfer_to_savings); 79 | } else if (tx[i]['operations'][y][0] === "feed_publish") { // price feed from a witness 80 | const feed_publish = tx[i]['operations'][y][1]; 81 | 82 | console.log(feed_publish); 83 | }else if (tx[i]['operations'][y][0] === "account_witness_vote") { // vote/unvote for a witness 84 | const account_witness_vote = tx[i]['operations'][y][1]; 85 | 86 | console.log(account_witness_vote); 87 | }else if (tx[i]['operations'][y][0] === "limit_order_create") { // Create a limit order on the internal market 88 | const limit_order_create = tx[i]['operations'][y][1]; 89 | 90 | console.log(limit_order_create); 91 | }else if (tx[i]['operations'][y][0] === "account_create_with_delegation") { // Create an account with delegation 92 | const account_create_with_delegation = tx[i]['operations'][y][1]; 93 | 94 | console.log(account_create_with_delegation); 95 | }else if (tx[i]['operations'][y][0] === "delete_comment") { // Delete a post/comment 96 | const delete_comment = tx[i]['operations'][y][1]; 97 | 98 | console.log(delete_comment); 99 | }else if (tx[i]['operations'][y][0] === "delegate_vesting_shares") { // price feed from a witness 100 | const delegate_vesting_shares = tx[i]['operations'][y][1]; 101 | 102 | console.log(delegate_vesting_shares); 103 | }else if (tx[i]['operations'][y][0] === "transfer_from_savings") { // withdrawal from saving account 104 | const transfer_from_savings = tx[i]['operations'][y][1]; 105 | 106 | console.log(transfer_from_savings); 107 | }else if (tx[i]['operations'][y][0] === "withdraw_vesting") { // power down 108 | const withdraw_vesting = tx[i]['operations'][y][1]; 109 | 110 | console.log(withdraw_vesting); 111 | } else if (tx[i]['operations'][y][0] === "account_witness_proxy") { // proxy witness vote 112 | const account_witness_proxy = tx[i]['operations'][y][1]; 113 | 114 | console.log(account_witness_proxy); 115 | } else if (tx[i]['operations'][y][0] === "account_create") { // account create without delegation 116 | const account_create = tx[i]['operations'][y][1]; 117 | 118 | console.log(account_create); 119 | }else if (tx[i]['operations'][y][0] === "cancel_transfer_from_savings") { // Cancel Transfer From Savings 120 | const cancel_transfer_from_savings = tx[i]['operations'][y][1]; 121 | 122 | console.log(cancel_transfer_from_savings); 123 | } 124 | else { 125 | var something = tx[i]['operations'][y]; 126 | console.log(something) 127 | } 128 | } 129 | } 130 | 131 | 132 | } 133 | 134 | 135 | /** 136 | * Main function tp start the stream 137 | * @param {int} from - Block from which to start streaming, most rpc nodes won't stream more than 100 blocks in one go so be careful 138 | */ 139 | async function main(from) { 140 | console.log("Starting parser"); 141 | 142 | let stream = null; 143 | 144 | if (from) { 145 | stream = steem.blockchain.getBlockNumberStream({from: lastblock}); 146 | } 147 | else 148 | stream = steem.blockchain.getBlockNumberStream(); 149 | 150 | stream.pipe(es.map(function (block, callback) { 151 | callback(null, parseBlock(block)) 152 | })); 153 | 154 | } 155 | 156 | 157 | main(); 158 | 159 | -------------------------------------------------------------------------------- /dsteem/block_feed/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "block_feed", 3 | "version": "1.0.0", 4 | "description": "block stream skeleton to easily act on various operations as they go live on the blockchain", 5 | "main": "comment.js", 6 | "dependencies": { 7 | "dsteem": "^0.8.6", 8 | "event-stream": "3.3.4" 9 | }, 10 | "devDependencies": {}, 11 | "scripts": { 12 | "test": "echo \"Error: no test specified\" && exit 1" 13 | }, 14 | "author": "Martin Lees", 15 | "license": "MIT" 16 | } 17 | -------------------------------------------------------------------------------- /dsteem/claim_account/claim_account.js: -------------------------------------------------------------------------------- 1 | var dsteem = require('dsteem'); 2 | 3 | var client = new dsteem.Client('https://api.steemit.com'); 4 | 5 | /** 6 | * claims a discounted account. 7 | * @param {String} creator - Name of the account that will claim the discounted account. 8 | * @param {String} active_key - Active key of the creator account 9 | */ 10 | function claim_account(creator, active_key) 11 | { 12 | return new Promise(resolve => { 13 | const wif = dsteem.PrivateKey.fromString(active_key); 14 | 15 | const fee = dsteem.Asset.from(0, 'STEEM'); 16 | 17 | const op = [ 18 | 'claim_account', 19 | { 20 | creator: creator, 21 | extensions: [], 22 | fee: fee 23 | }]; 24 | 25 | client.broadcast.sendOperations([op], wif).then(function (result) { 26 | console.log('Included in block: ' + result.block_num) 27 | resolve("="); 28 | }, function (error) { 29 | console.error(error); 30 | resolve("-"); 31 | }); 32 | }); 33 | } 34 | 35 | async function example() { 36 | await claim_account("username", "active_key"); 37 | 38 | } 39 | 40 | example(); -------------------------------------------------------------------------------- /dsteem/claim_account/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "claimAccount", 3 | "version": "1.0.0", 4 | "description": "Claim an account for free ", 5 | "main": "claimAccount.js", 6 | "dependencies": { 7 | "dsteem": "^0.10.1" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /dsteem/comment/comment.js: -------------------------------------------------------------------------------- 1 | var dsteem = require('dsteem'); 2 | 3 | var client = new dsteem.Client('https://api.steemit.com'); 4 | 5 | /** 6 | * Creates a comment on a steem post 7 | * @param {String} username - username of the account 8 | * @param {String} password - password of the account 9 | * @param {String} author - Author of the post to comment to 10 | * @param {String} permlink - permanent link of the post to comment to. eg : https://steemit.com/programming/@howo/introducting-steemsnippets the permlink is "introducting-steemsnippets" 11 | * @param {String} text - Content of the comment. 12 | * @param {String} [jsonMetadata] - Json string with additional tags, app name, etc, 13 | */ 14 | function comment(username, password, author, permlink, text, jsonMetadata) { 15 | var wif = dsteem.PrivateKey.fromLogin(username, password, 'posting') 16 | jsonMetadata = jsonMetadata || ''; 17 | var comment_permlink = new Date().toISOString().replace(/[^a-zA-Z0-9]+/g, '').toLowerCase(); 18 | 19 | client.broadcast.comment({ 20 | author: username, 21 | title : '', 22 | body : text, 23 | json_metadata : jsonMetadata, 24 | parent_author : author , 25 | parent_permlink: permlink, 26 | permlink : comment_permlink 27 | }, wif).then(function(result){ 28 | console.log('Included in block: ' + result.block_num) 29 | }, function(error) { 30 | console.error(error) 31 | }); 32 | } 33 | 34 | // example 35 | comment("username", "password", "howo", "introducting-steemsnippets", 'Woah nice article'); 36 | 37 | -------------------------------------------------------------------------------- /dsteem/comment/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "post", 3 | "version": "1.0.0", 4 | "description": "Comment on an article to the steem blockchain using the dsteem library", 5 | "main": "comment.js", 6 | "dependencies": { 7 | "dsteem": "^0.8.6" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /dsteem/create_discounted_account/create_discounted_account.js: -------------------------------------------------------------------------------- 1 | var dsteem = require('dsteem'); 2 | 3 | var client = new dsteem.Client('https://api.steemit.com'); 4 | 5 | /** 6 | * Creates a discounted account, note that you need to claim discounted accounts before being able to create them this way. 7 | * @param {String} creator - Name of the account that will create the new account. This account must have at least one claimed discounted account. 8 | * @param {String} active_key - Active key of the creator account 9 | * @param {String} username - username of the account to be created 10 | * @param {String} password - password of the account to be created. 11 | */ 12 | function create_discounted_account(creator, active_key, username, password) 13 | { 14 | return new Promise(resolve => { 15 | const wif = dsteem.PrivateKey.fromString(active_key); 16 | 17 | const prefix = client.addressPrefix; 18 | 19 | const ownerKey = dsteem.PrivateKey.fromLogin(username, password, 'owner').createPublic(prefix); 20 | let owner = dsteem.Authority.from(ownerKey); 21 | const activeKey = dsteem.PrivateKey.fromLogin(username, password, 'active').createPublic(prefix); 22 | let active = dsteem.Authority.from(activeKey); 23 | const postingKey = dsteem.PrivateKey.fromLogin(username, password, 'posting').createPublic(prefix); 24 | let posting = dsteem.Authority.from(postingKey); 25 | let memo_key = dsteem.PrivateKey.fromLogin(username, password, 'memo').createPublic(prefix); 26 | 27 | const metadata = {date: new Date()}; 28 | 29 | const create_op = [ 30 | 'create_claimed_account', 31 | { 32 | active, 33 | creator, 34 | extensions: [], 35 | json_metadata: metadata ? JSON.stringify(metadata) : '', 36 | memo_key, 37 | new_account_name: username, 38 | owner, 39 | posting, 40 | } 41 | ]; 42 | 43 | 44 | client.broadcast.sendOperations([create_op], wif).then(function (result) { 45 | console.log('Included in block: ' + result.block_num); 46 | resolve("="); 47 | }, function (error) { 48 | console.error(error); 49 | resolve("-"); 50 | }); 51 | }); 52 | } 53 | 54 | async function example() { 55 | const creator = "creator_account"; 56 | const active_key = "creator_active_key"; 57 | const new_account = "new_account_username"; 58 | const new_account_password = "baguette"; 59 | await create_discounted_account(creator, active_key, new_account, new_account_password); 60 | } 61 | 62 | example(); -------------------------------------------------------------------------------- /dsteem/create_discounted_account/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Create_discounted_account", 3 | "version": "1.0.0", 4 | "description": "Creates a discounted account ", 5 | "main": "create_discounted_account.js", 6 | "dependencies": { 7 | "dsteem": "^0.10.1" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /dsteem/getContent/getContent.js: -------------------------------------------------------------------------------- 1 | var dsteem = require('dsteem'); 2 | 3 | var client = new dsteem.Client('https://api.steemit.com'); 4 | 5 | /** 6 | * Equivalent of steem-js's getContent in one function. 7 | * @param {String} author - Author of the post to getContent to 8 | * @param {String} permlink - permanent link of the post to getContent to. eg : https://steemit.com/programming/@howo/introducting-steemsnippets the permlink is "introducting-steemsnippets" 9 | */ 10 | function getContent(author, permlink) { 11 | return new Promise(async resolve => { 12 | const article = await client.database.getDiscussions('blog', {tag: author, start_author: author, start_permlink: permlink, limit: 1}); 13 | return resolve(article); 14 | }); 15 | } 16 | 17 | // example 18 | getContent("howo", "steem-reward-manager-conversion-update"); 19 | 20 | -------------------------------------------------------------------------------- /dsteem/getContent/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "post", 3 | "version": "1.0.0", 4 | "description": "Comment on an article to the steem blockchain using the dsteem library", 5 | "main": "comment.js", 6 | "dependencies": { 7 | "dsteem": "^0.8.6" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /dsteem/get_active_votes/get_active_votes.js: -------------------------------------------------------------------------------- 1 | var rp = require('request-promise-native'); 2 | var fs = require('fs'); 3 | var dsteem = require('dsteem'); 4 | 5 | var client = new dsteem.Client('https://api.steemit.com'); 6 | 7 | const cache_path = __dirname+"/curator_cache"; 8 | 9 | /** 10 | * Save voter data to a cache file 11 | * @param username of the voter 12 | * @param author of the oldest active post voted 13 | * @param permlink of the oldest active post voted 14 | */ 15 | function save_curator_data(username, author, permlink) 16 | { 17 | let current_json = {}; 18 | 19 | if (fs.existsSync(cache_path)) { 20 | current_json = JSON.parse(fs.readFileSync(cache_path).toString()); 21 | } 22 | 23 | current_json[username] = {author : author, permlink : permlink} 24 | 25 | fs.writeFileSync(cache_path, JSON.stringify(current_json)); 26 | } 27 | 28 | /** 29 | * Returns the vote data of an user 30 | * @param username of the voter 31 | * @returns {*} the author and permlink of the oldest active post voted. 32 | */ 33 | function get_voter_data(username) 34 | { 35 | if (fs.existsSync(cache_path)) { 36 | let data = JSON.parse(fs.readFileSync(cache_path).toString()); 37 | 38 | if (data[username] !== undefined) 39 | return {author : data[username].author, pemlink : data[username].permlink}; 40 | else 41 | return {author : "", pemlink : ""} 42 | } else 43 | { 44 | return {author : "", pemlink : ""} 45 | } 46 | } 47 | 48 | /** 49 | * Removes the votes that are older than 7 days from an array of votes 50 | * @param vote_list array of votes object 51 | * @returns {*} a cleaned list of votes. 52 | */ 53 | function remove_unactive_votes(vote_list) 54 | { 55 | const seven_days_ago = Math.floor(new Date().getTime() / 1000) - 86400 * 7; 56 | 57 | for (let i = 0; i < vote_list.length; i++) 58 | { 59 | const created_date = Math.floor(Date.parse(vote_list[i].last_update) / 1000); 60 | 61 | if (created_date - seven_days_ago > 0 && vote_list[i].num_changes === 0) { 62 | 63 | const elements_to_keep = vote_list.length - i; 64 | return vote_list.slice(vote_list.length - elements_to_keep) 65 | } 66 | } 67 | return []; 68 | } 69 | 70 | /** 71 | * Gets all the active votes of a voter and cleans them. 72 | * @param voter to grab votes from 73 | * @param author (optional) author of a post to start the search from, post has to have been voted by the voter 74 | * @param permlink (optional) permlink of a post to start the search from, post has to have been voted by the voter 75 | * @returns {Promise} list of votes 76 | */ 77 | function list_votes(voter, author = "", permlink = "") 78 | { 79 | return new Promise(async resolve => { 80 | let total_votes = []; 81 | let votes = await get_list_votes(voter, author, permlink); 82 | 83 | if (votes.error !== undefined) 84 | return resolve(votes); 85 | 86 | votes = votes.votes; 87 | 88 | 89 | votes = clean_votes(votes, voter); 90 | total_votes.push(...votes); 91 | 92 | while (votes.length === 1000) { 93 | votes = await get_list_votes(voter, votes[999].author, votes[999].permlink); 94 | 95 | if (votes.error !== undefined) 96 | return resolve(votes); 97 | 98 | votes = votes.votes; 99 | votes = clean_votes(votes, voter); 100 | total_votes.push(...votes); 101 | } 102 | 103 | return resolve(remove_unactive_votes(total_votes)); 104 | }); 105 | } 106 | 107 | /** 108 | * Calls the rpc to get the list of votes. 109 | * @param voter to grab votes from 110 | * @param author (optional) author of a post to start the search from, post has to have been voted by the voter 111 | * @param permlink (optional) permlink of a post to start the search from, post has to have been voted by the voter 112 | * @returns {Promise} list of votes 113 | */ 114 | function get_list_votes(voter, author, permlink) 115 | { 116 | return new Promise(resolve => { 117 | var options = { 118 | method: 'POST', 119 | uri: 'https://api.steemit.com', 120 | body: { 121 | jsonrpc : "2.0", 122 | method : "database_api.list_votes", 123 | params : { 124 | start: [voter, author, permlink], 125 | limit: 1000, 126 | order: "by_voter_comment", 127 | }, 128 | id : 1 129 | }, 130 | json: true // Automatically stringifies the body to JSON 131 | }; 132 | 133 | rp(options) 134 | .then(function (body) { 135 | if (body.error) { 136 | console.error(body.error.message); 137 | return resolve({error : body.error, votes : []}) 138 | } 139 | return resolve({votes : body.result.votes}); 140 | }) 141 | .catch(function (err) { 142 | console.log(err); 143 | return resolve({error : err, votes : []}) 144 | }); 145 | }); 146 | } 147 | 148 | /** 149 | * Removes votes that are not from the voter in a list of votes 150 | * @param votes list of votes 151 | * @param voter that we want the votes from 152 | * @returns {Array} cleaned list of votes 153 | */ 154 | function clean_votes(votes, voter) 155 | { 156 | let clean_array = []; 157 | 158 | for (let i = 0; i < votes.length; i++) 159 | { 160 | if (votes[i].voter === voter) 161 | clean_array.push(votes[i]); 162 | } 163 | 164 | return clean_array; 165 | 166 | } 167 | 168 | /** 169 | * Allows to set a sleep in the program 170 | * @param time to sleep in seconds 171 | * @returns {Promise} 172 | */ 173 | function wait(time) 174 | { 175 | return new Promise(resolve => { 176 | setTimeout(() => resolve('☕'), time*1000); // miliseconds to seconds 177 | }); 178 | } 179 | 180 | 181 | 182 | /** 183 | * Checks if a post is awaiting payout 184 | * @param {string} author - Username of the user who created the post 185 | * @param {string} permlink - permlink of the post 186 | */ 187 | function is_post_active(author, permlink) 188 | { 189 | return new Promise(async resolve => { 190 | var _7_days_ago = Math.floor(new Date().getTime() / 1000) - 86400 * 7; 191 | const post = await client.database.call("get_content", [author, permlink]); 192 | 193 | var created_date = Math.floor(Date.parse(post['created']) / 1000); 194 | 195 | if (created_date - _7_days_ago > 0) { 196 | resolve(true) 197 | } else { 198 | resolve(false) 199 | } 200 | }); 201 | } 202 | 203 | /** 204 | * Gets all the active votes from an user 205 | * @param username to grab the votes from 206 | * @returns {Promise} list of active votes. 207 | */ 208 | 209 | function get_active_votes(username) 210 | { 211 | return new Promise(async resolve => { 212 | let active_votes = []; 213 | 214 | let curator_data = get_voter_data(username) 215 | 216 | let author = curator_data.author; 217 | let permlink = curator_data.pemlink; 218 | 219 | let result = await list_votes(username, author, permlink); 220 | 221 | while (result.error !== undefined) 222 | { 223 | console.log("get_account_votes error, waiting"); 224 | await wait(0.5); 225 | result = await list_votes(username, author, permlink); 226 | } 227 | 228 | 229 | if (result.length === 0) 230 | return resolve([]); 231 | 232 | author = result[0].author; 233 | permlink = result[0].permlink; 234 | 235 | 236 | save_curator_data(username, author, permlink); 237 | 238 | for (let i = 0; i < result.length; i++) { 239 | const active = await is_post_active(result[i].author, result[i].permlink); 240 | if (active) 241 | active_votes.push(result[i]) 242 | } 243 | resolve(active_votes); 244 | }); 245 | } 246 | 247 | 248 | async function example() { 249 | const votes = await get_active_votes("howo", "", ""); 250 | console.log(votes); 251 | } 252 | 253 | example(); -------------------------------------------------------------------------------- /dsteem/get_active_votes/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "get_active_votes", 3 | "version": "1.0.0", 4 | "description": "Gets the active votes from one author using list_votes", 5 | "main": "comment.js", 6 | "dependencies": { 7 | "dsteem": "^0.11.2", 8 | "request": "^2.88.0", 9 | "request-promise-native": "^1.0.5" 10 | }, 11 | "devDependencies": {}, 12 | "scripts": { 13 | "test": "echo \"Error: no test specified\" && exit 1" 14 | }, 15 | "author": "Martin Lees", 16 | "license": "MIT" 17 | } 18 | -------------------------------------------------------------------------------- /dsteem/get_all_comments/get_all_comments.js: -------------------------------------------------------------------------------- 1 | const utils = require('./utils'); 2 | const moment = require("moment"); 3 | const dsteem = require('dsteem'); 4 | 5 | const client = new dsteem.Client('https://api.steemit.com'); 6 | 7 | function build_get_replies(reply) 8 | { 9 | return new Promise(async resolve => { 10 | 11 | reply.active_votes = await client.database.call("get_active_votes", [reply.author, reply.permlink]); 12 | 13 | const userTimezoneOffset = new Date().getTimezoneOffset() * 60000; 14 | const chosenDate = moment.unix(new Date(reply.created).getTime() / 1000); 15 | reply.unix = chosenDate.unix(); 16 | reply.date = chosenDate.from(new Date().getTime() + userTimezoneOffset); 17 | 18 | reply.reputation = utils.repLog10(reply.author_reputation); 19 | 20 | const total_payout = 21 | parseFloat(reply.pending_payout_value) + 22 | parseFloat(reply.total_payout_value) + 23 | parseFloat(reply.curator_payout_value); 24 | 25 | reply.total_payout = (Math.floor(parseFloat(total_payout) * 100) / 100); 26 | 27 | reply.upvotes = reply.active_votes.length; 28 | 29 | const voteRshares = reply.active_votes.reduce((a, b) => a + parseFloat(b.rshares), 0); 30 | 31 | const ratio = (voteRshares === 0 ? 0 : reply.total_payout / voteRshares); 32 | 33 | reply.active_votes.map((vote) => { 34 | vote.value = Math.floor((vote.rshares * ratio)*100)/100; 35 | if (vote.percent === 0) 36 | reply.active_votes.splice(reply.active_votes.indexOf(vote), 1) 37 | }); 38 | 39 | reply.active_votes.sort(utils.compare_votes); 40 | 41 | 42 | if (reply.children > 0) 43 | { 44 | reply.replies = await client.database.call("get_content_replies", [reply.author, reply.permlink]); 45 | 46 | 47 | for (let i = 0; i < reply.replies.length; i++) { 48 | reply.replies[i] = await build_get_replies(reply.replies[i]); 49 | } 50 | 51 | return resolve(reply); 52 | } else 53 | { 54 | return resolve(reply); 55 | } 56 | 57 | 58 | }) 59 | } 60 | 61 | function build_comment_data(author, permlink) 62 | { 63 | return new Promise(async resolve => { 64 | let post = await client.database.call("get_content", [author, permlink]).catch(function (err) { 65 | console.error(err); 66 | }); 67 | 68 | if (post['root_permlink'] === "" && post['root_author'] === "" ) 69 | return resolve(post); 70 | 71 | post.replies = await client.database.call("get_content_replies", [author, permlink]).catch(function (err) { 72 | return resolve({error: err.message, comments: ""}); 73 | }); 74 | 75 | for (let i = 0; i < post.replies.length; i++) { 76 | post.replies[i] = await build_get_replies(post.replies[i]); 77 | } 78 | 79 | return resolve(post); 80 | }); 81 | } 82 | 83 | /** 84 | * 85 | * From a comment (username and permlink) get the original post(username and permlink) on which it was done 86 | * @param {String} author - username of the author 87 | * @param {String} permlink - permlink of the post 88 | * @return {Object} an object with all the comments ordered 89 | */ 90 | 91 | function get_all_comments(author, permlink) 92 | { 93 | return new Promise(async resolve => { 94 | 95 | if (author === "" || permlink === "") 96 | return resolve({error:"Post not found", comments : ""}); 97 | 98 | const post = await build_comment_data(author, permlink); 99 | 100 | if (post['root_permlink'] === "" && post['root_author'] === "" ) 101 | return resolve({error:"Post not found", comments : ""}); 102 | 103 | return resolve({comments : post}); 104 | }); 105 | } 106 | 107 | async function test() { 108 | var data = await get_all_comments("petanque", "testcomments-xylmwuwi6p"); 109 | 110 | if (data.comments === "" && data.error !== undefined) { 111 | console.error(data.error); 112 | } 113 | } 114 | 115 | test(); 116 | -------------------------------------------------------------------------------- /dsteem/get_all_comments/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "get_all_comments", 3 | "version": "1.0.0", 4 | "description": "Gets all the comments from a post", 5 | "main": "get_all_comments.js", 6 | "dependencies": { 7 | "dsteem": "^0.8.6", 8 | "moment": "^2.22.2", 9 | "remark": "^10.0.1", 10 | "remark-html": "^9.0.0", 11 | "sanitize-html": "^1.19.1", 12 | "strip-markdown": "^3.0.2", 13 | "xss": "^0.3.4" 14 | }, 15 | "devDependencies": {}, 16 | "scripts": { 17 | "test": "echo \"Error: no test specified\" && exit 1" 18 | }, 19 | "author": "Martin Lees", 20 | "license": "MIT" 21 | } 22 | -------------------------------------------------------------------------------- /dsteem/get_all_comments/utils.js: -------------------------------------------------------------------------------- 1 | const remark_html = require('remark-html'); 2 | const remark_markdown = require('remark-parse'); 3 | const remark_unified = require('unified'); 4 | var sanitizeHtml = require('sanitize-html'); 5 | 6 | function log10(str) { 7 | const leadingDigits = parseInt(str.substring(0, 4)); 8 | const log = Math.log(leadingDigits) / Math.LN10 + 0.00000001; 9 | const n = str.length - 1; 10 | return n + (log - parseInt(log)); 11 | } 12 | 13 | const repLog10 = rep2 => { 14 | if (rep2 == null) return rep2; 15 | let rep = String(rep2); 16 | const neg = rep.charAt(0) === '-'; 17 | rep = neg ? rep.substring(1) : rep; 18 | 19 | let out = log10(rep); 20 | if (isNaN(out)) out = 0; 21 | out = Math.max(out - 9, 0); // @ -9, $0.50 earned is approx magnitude 1 22 | out = (neg ? -1 : 1) * out; 23 | out = out * 9 + 25; // 9 points per magnitude. center at 25 24 | // base-line 0 to darken and < 0 to auto hide (grep rephide) 25 | out = parseInt(out); 26 | return out; 27 | }; 28 | 29 | 30 | function replaceAll(str, find, replace) { 31 | return str.replace(new RegExp(find, 'g'), replace); 32 | } 33 | 34 | function parse_imgs(text) { 35 | let finaltext = ""; 36 | const split = text.split(" 1) { 39 | for (let i = 0; i < split.length; i++) { 40 | if (i === 0) { 41 | finaltext += split[0].substring(0, split[0].length); 42 | continue; 43 | } 44 | 45 | let image = split[i].substr(6) 46 | image = image.substr(0, image.indexOf('"')); 47 | 48 | finaltext += "image "; 49 | 50 | } 51 | return finaltext; 52 | } 53 | 54 | return text; 55 | } 56 | 57 | function count_votes(votes) 58 | { 59 | let upvotes = 0; 60 | let downvotes = 0; 61 | 62 | votes.map(vote => { 63 | if (vote.percent > 0) 64 | upvotes += 1; 65 | else 66 | downvotes += 1; 67 | }); 68 | 69 | return {upvotes : upvotes, downvotes : downvotes}; 70 | 71 | } 72 | 73 | 74 | function parse_text(text) 75 | { 76 | return new Promise(resolve => { 77 | remark_unified() 78 | .use(remark_markdown) 79 | .use(remark_html) 80 | .process(text, function (err, file) { 81 | if (err) { 82 | console.error(err); 83 | return resolve("[Comment failed to load]") 84 | } 85 | 86 | text = String(file); 87 | text = replaceAll(text, "\n", "
"); 88 | text = text.replace(/(@[a-zA-Z-]{3,16})/ig, "$1"); 89 | let cleaned_html = sanitizeHtml(text, { 90 | allowedTags: ['a', 'b', 'i', 'strong', 'em', 'strike', 'br', 'img', 'div', 'center'], 91 | allowedAttributes: { 92 | 'a': [ 'href' ], 93 | 'img' : ['src'], 94 | 'div' : ['class'] 95 | } 96 | }); 97 | 98 | cleaned_html = parse_imgs(cleaned_html); 99 | 100 | 101 | return resolve(cleaned_html); 102 | }) 103 | }); 104 | } 105 | 106 | function compare_votes(a,b) { 107 | if (a.value < b.value) 108 | return 1; 109 | if (a.value > b.value) 110 | return -1; 111 | return 0; 112 | } 113 | 114 | module.exports = { 115 | repLog10, 116 | parse_text, 117 | compare_votes 118 | } -------------------------------------------------------------------------------- /dsteem/get_downvoting_power/get_downvoting_power.js: -------------------------------------------------------------------------------- 1 | var dsteem = require('dsteem'); 2 | 3 | var client = new dsteem.Client('https://api.steemit.com'); 4 | 5 | /** 6 | * Gets the downvoting power percentage 7 | * @param {String} username - Username to get the downvoting pool percentage from 8 | */ 9 | function get_downvoting_power(username) { 10 | 11 | return new Promise(async resolve => { 12 | let account = await client.database.getAccounts([username]); 13 | 14 | account = account[0]; 15 | 16 | const totalShares = parseFloat(account.vesting_shares) + parseFloat(account.received_vesting_shares) - parseFloat(account.delegated_vesting_shares) - parseFloat(account.vesting_withdraw_rate); 17 | 18 | const elapsed = Math.floor(Date.now() / 1000) - account.downvote_manabar.last_update_time; 19 | const maxMana = totalShares * 1000000 / 4; 20 | // 432000 sec = 5 days 21 | let currentMana = parseFloat(account.downvote_manabar.current_mana) + elapsed * maxMana / 432000; 22 | 23 | if (currentMana > maxMana) { 24 | currentMana = maxMana; 25 | } 26 | 27 | const currentManaPerc = currentMana * 100 / maxMana; 28 | 29 | return resolve(currentManaPerc); 30 | }); 31 | } 32 | 33 | // example 34 | async function test() 35 | { 36 | console.log(await get_downvoting_power("howo")); 37 | } 38 | 39 | test(); 40 | -------------------------------------------------------------------------------- /dsteem/get_downvoting_power/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "get_downvoting_power", 3 | "version": "1.0.0", 4 | "description": "Gets the downvoting power percentage", 5 | "main": "comment.js", 6 | "dependencies": { 7 | "dsteem": "^0.8.6" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /dsteem/post/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "post", 3 | "version": "1.0.0", 4 | "description": "Posts an article to the steem blockchain using the dsteem library", 5 | "main": "post.js", 6 | "dependencies": { 7 | "dsteem": "^0.8.6" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /dsteem/post/post.js: -------------------------------------------------------------------------------- 1 | var dsteem = require('dsteem'); 2 | 3 | var client = new dsteem.Client('https://api.steemit.com'); 4 | /** 5 | * Posts an article on the steem blockchain 6 | * @param {String} username - username of the account 7 | * @param {String} password - password of the account 8 | * @param {String} main_tag - The main tag for the post 9 | * @param {String} title - Title of the post 10 | * @param {String} body - body (content) of the post. 11 | * @param {String} [jsonMetadata] - Json string with additional tags, app name, etc, 12 | * @param {String} [permlink] - permanent link, by default it's the date + -post. eg : 20171237t122520625z-post 13 | */ 14 | function post(username, password, main_tag, title, body, jsonMetadata, permlink) { 15 | var wif = dsteem.PrivateKey.fromLogin(username, password, 'posting') 16 | // By default permlink will be the date 17 | permlink = permlink || new Date().toISOString().replace(/[^a-zA-Z0-9]+/g, '').toLowerCase(); 18 | jsonMetadata = jsonMetadata || ""; 19 | 20 | client.broadcast.comment({ 21 | author: username, 22 | title : title, 23 | body : body, 24 | json_metadata : jsonMetadata, 25 | parent_author : '' , 26 | parent_permlink: main_tag, 27 | permlink : permlink 28 | }, wif).then(function(result){ 29 | console.log('Included in block: ' + result.block_num) 30 | }, function(error) { 31 | console.error(error) 32 | }); 33 | 34 | } 35 | // example 36 | post("username", "Password", "tag1", "title", "body", '{"tags": ["tag2", "tag3"]}'); 37 | 38 | -------------------------------------------------------------------------------- /dsteem/power_up/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "post", 3 | "version": "1.0.0", 4 | "description": "Comment on an article to the steem blockchain using the dsteem library", 5 | "main": "comment.js", 6 | "dependencies": { 7 | "dsteem": "^0.8.6" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /dsteem/power_up/power_up.js: -------------------------------------------------------------------------------- 1 | var dsteem = require('dsteem'); 2 | 3 | var client = new dsteem.Client('https://api.steemit.com'); 4 | 5 | /** 6 | * Powers up x amounts of steem 7 | * @param from Account from which the liquid steem will be drained 8 | * @param to Account on which the liquid steem will be powered up (can be the same as the account from which the steem will be drained) 9 | * @param amount Amount of tokens that you want to power up, note that it must be written like this : x.xxx unit eg : '1.265 STEEM' or '0.010 STEEM' 10 | * @param active_key Active key of the from account. 11 | * @returns {Promise} Result of the operation. 12 | */ 13 | function power_up(from, to, amount, active_key) { 14 | return new Promise(async resolve => { 15 | 16 | const privateKey = dsteem.PrivateKey.fromString( 17 | active_key 18 | ); 19 | const op = [ 20 | 'transfer_to_vesting', 21 | { 22 | from: from, 23 | to: to, 24 | amount: amount, 25 | }, 26 | ]; 27 | const result = await client.broadcast.sendOperations([op], privateKey).catch(function(error) { 28 | console.error(error); 29 | } 30 | ); 31 | 32 | return resolve(result); 33 | 34 | }); 35 | } 36 | 37 | // example 38 | power_up("howo", "howo", "1.000 STEEM", "private active key"); 39 | 40 | -------------------------------------------------------------------------------- /dsteem/vote/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vote", 3 | "version": "1.0.0", 4 | "description": "How to cast a vote on an article using dsteem", 5 | "main": "vote.js", 6 | "dependencies": { 7 | "dsteem": "^0.8.6" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /dsteem/vote/vote.js: -------------------------------------------------------------------------------- 1 | var dsteem = require('dsteem'); 2 | 3 | var client = new dsteem.Client('https://api.steemit.com'); 4 | 5 | /** 6 | * Creates an account, note that almost no validation is done. 7 | * @param {String} username - username of the voter account 8 | * @param {String} password - password of the voter account 9 | * @param {String} author - Author of the post 10 | * @param {String} url - permlink of the post eg : 11 | * @param {String} permlink - permanent link of the post to comment to. eg : https://steemit.com/programming/@howo/introducting-steemsnippets the permlink is "introducting-steemsnippets" 12 | * @param {int} weight - Power of the vote, can range from -10000 to 10000, 10000 equals a 100% upvote. -10000 equals a 100% flag. 13 | */ 14 | function vote(username, password, author, permlink, weight) 15 | { 16 | var wif = dsteem.PrivateKey.fromLogin(username, password, 'posting') 17 | 18 | client.broadcast.vote({ 19 | voter: username, 20 | author: author, 21 | permlink: permlink, 22 | weight: weight 23 | }, wif).then(function(result){ 24 | console.log('Included in block: ' + result.block_num) 25 | }, function(error) { 26 | console.error(error) 27 | }); 28 | 29 | } 30 | 31 | // example : give a 100% upvote to the post https://steemit.com/programming/@howo/introducting-steemsnippets 32 | vote("username", "password", "howo", "introducting-steemsnippets", 10000); -------------------------------------------------------------------------------- /steem-python/get_biggest_followers/get_biggest_followers.py: -------------------------------------------------------------------------------- 1 | from steem.account import Account 2 | from steem import Steem 3 | from steem import converter 4 | import operator 5 | 6 | 7 | # Note : This is fairly slow and an probably be optimized but it can give you a sense of how to do things 8 | acc = Account( 9 | "acidyo", 10 | steemd_instance=Steem( 11 | nodes=["https://api.steemit.com"]) 12 | ) 13 | 14 | followers = {} 15 | 16 | for follower in acc.get_followers(): 17 | print(follower) 18 | follower_obj = Account( 19 | follower, 20 | steemd_instance=Steem( 21 | nodes=["https://api.steemit.com"]) 22 | ) 23 | total_sp = 0 24 | sp_vests = float(follower_obj['vesting_shares'][:-6]) 25 | recieved_vests = float(follower_obj['received_vesting_shares'][:-6]) 26 | delegated_vests = float(follower_obj['delegated_vesting_shares'][:-6]) 27 | total_sp = sp_vests + recieved_vests - delegated_vests 28 | sp = (round(follower_obj.converter.vests_to_sp(total_sp), 3)) # convert vests to steem power 29 | followers.update({follower: sp}) 30 | 31 | sorted_followers = sorted(followers.items(), key=operator.itemgetter(1)) 32 | 33 | for follower in sorted_followers: 34 | print(follower) 35 | -------------------------------------------------------------------------------- /steem-python/get_biggest_followers/requirements.txt: -------------------------------------------------------------------------------- 1 | steem -------------------------------------------------------------------------------- /steem-python/post/post.py: -------------------------------------------------------------------------------- 1 | from steem import Steem 2 | 3 | """ Create a new post. 4 | If this post is intended as a reply/comment, `reply_identifier` needs to be set with the identifier of the parent 5 | post/comment (eg. `@author/permlink`). 6 | 7 | Optionally you can also set json_metadata, comment_options and upvote the newly created post as an author. 8 | 9 | Setting category, tags or community will override the values provided in json_metadata and/or comment_options 10 | where appropriate. 11 | 12 | Args: 13 | username (str) : Username of the account posting 14 | wif (str) : posting key of the account posting 15 | title (str): Title of the post 16 | body (str): Body of the post/comment 17 | author (str): Account are you posting from 18 | permlink (str): Manually set the permlink (defaults to None). 19 | If left empty, it will be derived from title automatically. 20 | reply_identifier (str): Identifier of the parent post/comment (only if this post is a reply/comment). 21 | json_metadata (str, dict): JSON meta object that can be attached to the post. 22 | comment_options (str, dict): JSON options object that can be attached to the post. 23 | Example:: 24 | 25 | comment_options = { 26 | 'max_accepted_payout': '1000000.000 SBD', 27 | 'percent_steem_dollars': 10000, 28 | 'allow_votes': True, 29 | 'allow_curation_rewards': True, 30 | 'extensions': [[0, { 31 | 'beneficiaries': [ 32 | {'account': 'account1', 'weight': 5000}, 33 | {'account': 'account2', 'weight': 5000}, 34 | ]} 35 | ]] 36 | } 37 | 38 | community (str): (Optional) Name of the community we are posting into. This will also override the 39 | community specified in `json_metadata`. 40 | tags (str, list): (Optional) A list of tags (5 max) to go with the post. This will also override the 41 | tags specified in `json_metadata`. The first tag will be used as a 'category'. 42 | If provided as a string, it should be space separated. 43 | beneficiaries (list of dicts): (Optional) A list of beneficiaries for posting reward distribution. 44 | This argument overrides beneficiaries as specified in `comment_options`. 45 | 46 | For example, if we would like to split rewards between account1 and account2:: 47 | 48 | beneficiaries = [ 49 | {'account': 'account1', 'weight': 5000}, 50 | {'account': 'account2', 'weight': 5000} 51 | ] 52 | 53 | self_vote (bool): (Optional) Upvote the post as author, right after posting. 54 | """ 55 | def post(username, wif, title, body, permlink=None, reply_identifier=None, json_metadata=None, comment_options=None, community=None, tags=None, beneficiaries=None, self_vote=False): 56 | s = Steem(keys=wif, 57 | nodes=["https://api.steemit.com", "https://rpc.buildteam.io"]) 58 | s.commit.post(title, body, username, permlink, reply_identifier, json_metadata, comment_options, community, tags, beneficiaries, self_vote) 59 | 60 | # example : 61 | 62 | post("username", "posting key" ,title="Python Test", body="blank", tags=['spam','test'], self_vote=False) 63 | -------------------------------------------------------------------------------- /steem-python/post/requirements.txt: -------------------------------------------------------------------------------- 1 | steem -------------------------------------------------------------------------------- /steem-python/vote/requirements.txt: -------------------------------------------------------------------------------- 1 | steem -------------------------------------------------------------------------------- /steem-python/vote/vote.py: -------------------------------------------------------------------------------- 1 | from steem import Steem 2 | 3 | def vote(username, wif, identifier, weight): 4 | """ Vote for a post 5 | :param str username: Username of the account voting 6 | :param str wif: posting key of the account voting 7 | :param str identifier: Identifier for the post to upvote Takes 8 | the form ``@author/permlink`` 9 | :param float weight: Voting weight. Range: -100.0 - +100.0. May 10 | not be 0.0 11 | :param str account: Voter to use for voting. (Optional) 12 | 13 | If ``voter`` is not defines, the ``default_account`` will be taken or 14 | a ValueError will be raised 15 | 16 | .. code-block:: python 17 | 18 | steempy set default_account 19 | """ 20 | s = Steem(keys=wif, 21 | nodes=["https://api.steemit.com", "https://rpc.buildteam.io"]) 22 | s.commit.vote(identifier=identifier, weight=weight, account=username) 23 | 24 | #example : 25 | 26 | vote("username", "posting key", "@howo/introducting-steemsnippets" , 100) -------------------------------------------------------------------------------- /steemconnect/check_token/check_token.js: -------------------------------------------------------------------------------- 1 | const sc2 = require('sc2-sdk'); 2 | 3 | /** 4 | * Checks if an access token/username pair is correct 5 | * @param {String} username - username of the account 6 | * @param {String} access_token - Access token associated with the account 7 | @returns {Promise.} Array with one or two elements. First one is set to True if the access token is correct, or false and the error (aka the reason) will be stored in the second element. 8 | */ 9 | function sc_valid(username, access_token) 10 | { 11 | return new Promise(resolve => { 12 | 13 | let api = sc2.Initialize({}); 14 | 15 | api.setAccessToken(access_token); 16 | 17 | api.me(function (err, res) { 18 | if (err) 19 | return resolve([false, err]); 20 | 21 | if (res.name === username) 22 | return resolve([true]); 23 | 24 | return resolve([true]); 25 | }); 26 | }); 27 | } 28 | 29 | 30 | //Example 31 | async function example() 32 | { 33 | const result = await sc_valid("howo", "bad access token") 34 | if (result[0]) // if the result is true 35 | { 36 | console.log("Access token is correct ! ") 37 | } 38 | else 39 | { 40 | console.log(result[1]); 41 | 42 | /* Should output : 43 | { SDKError: sc2-sdk error 44 | name: 'SDKError', 45 | error: 'invalid_grant', 46 | error_description: 'The token has invalid role' 47 | } 48 | */ 49 | } 50 | } 51 | 52 | example() -------------------------------------------------------------------------------- /steemconnect/check_token/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "check_token", 3 | "version": "1.0.0", 4 | "description": "Checks the validity of an access token", 5 | "main": "check_token.js", 6 | "dependencies": { 7 | "sc2-sdk": "^1.0.2" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/account_update2/account_update2.js: -------------------------------------------------------------------------------- 1 | var steem = require('steem'); 2 | steem.api.setOptions({url: 'https://api.steemit.com'}); 3 | 4 | function broadcast(tx, wif) 5 | { 6 | return new Promise(resolve => { 7 | steem.broadcast.send(tx, {wif}, async function (err, result) { 8 | return resolve(result) 9 | }); 10 | }); 11 | } 12 | 13 | // example 14 | // if you get error, make sure that you have the latest steem-js version. 15 | async function account_update2(json_metadata, posting_key) { 16 | return new Promise(async resolve => { 17 | 18 | let ops = []; 19 | 20 | let username = "howo"; 21 | 22 | ops.push(['account_update2', { 23 | 'account': username, 24 | "posting_json_metadata": JSON.stringify(json_metadata), 25 | "json_metadata": "" 26 | }]); 27 | 28 | const result = await broadcast({operations: ops, extensions: []}, posting_key) 29 | return resolve(result) 30 | }); 31 | } 32 | 33 | async function main() { 34 | const result = await account_update2({profile: {location : "somewhere..."}}, "posting key"); 35 | console.log(result) 36 | } 37 | 38 | main(); 39 | -------------------------------------------------------------------------------- /steemjs/account_update2/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "post_exists", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "@steemit/libcrypto": { 8 | "version": "1.0.1", 9 | "resolved": "https://registry.npmjs.org/@steemit/libcrypto/-/libcrypto-1.0.1.tgz", 10 | "integrity": "sha512-g2y4OrELuPGLLu3GjVaPbVvY/K+4oPGOrv9ec013o/ZB76R9UQ1ufYD9RM5tKxHXpFhzj2k0JgoKYWkdVheFVA==" 11 | }, 12 | "@steemit/rpc-auth": { 13 | "version": "1.1.1", 14 | "resolved": "https://registry.npmjs.org/@steemit/rpc-auth/-/rpc-auth-1.1.1.tgz", 15 | "integrity": "sha512-Eb8BW3O1y4+/+Dbf+LqGVmgXYqyfHxP9mBlmzkpjXiIepTpxoK90NIGrneqcnEGq0TR2nSt4BVv9Ur9c+hxoig==", 16 | "requires": { 17 | "@steemit/libcrypto": "^1.0.1" 18 | } 19 | }, 20 | "async-limiter": { 21 | "version": "1.0.1", 22 | "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", 23 | "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==" 24 | }, 25 | "base-x": { 26 | "version": "3.0.7", 27 | "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.7.tgz", 28 | "integrity": "sha512-zAKJGuQPihXW22fkrfOclUUZXM2g92z5GzlSMHxhO6r6Qj+Nm0ccaGNBzDZojzwOMkpjAv4J0fOv1U4go+a4iw==", 29 | "requires": { 30 | "safe-buffer": "^5.0.1" 31 | } 32 | }, 33 | "base64-js": { 34 | "version": "1.3.1", 35 | "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz", 36 | "integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==" 37 | }, 38 | "bigi": { 39 | "version": "1.4.2", 40 | "resolved": "https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz", 41 | "integrity": "sha1-nGZalfiLiwj8Bc/XMfVhhZ1yWCU=" 42 | }, 43 | "bluebird": { 44 | "version": "3.7.2", 45 | "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", 46 | "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==" 47 | }, 48 | "browserify-aes": { 49 | "version": "1.2.0", 50 | "resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", 51 | "integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==", 52 | "requires": { 53 | "buffer-xor": "^1.0.3", 54 | "cipher-base": "^1.0.0", 55 | "create-hash": "^1.1.0", 56 | "evp_bytestokey": "^1.0.3", 57 | "inherits": "^2.0.1", 58 | "safe-buffer": "^5.0.1" 59 | } 60 | }, 61 | "bs58": { 62 | "version": "4.0.1", 63 | "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz", 64 | "integrity": "sha1-vhYedsNU9veIrkBx9j806MTwpCo=", 65 | "requires": { 66 | "base-x": "^3.0.2" 67 | } 68 | }, 69 | "buffer": { 70 | "version": "5.4.3", 71 | "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.4.3.tgz", 72 | "integrity": "sha512-zvj65TkFeIt3i6aj5bIvJDzjjQQGs4o/sNoezg1F1kYap9Nu2jcUdpwzRSJTHMMzG0H7bZkn4rNQpImhuxWX2A==", 73 | "requires": { 74 | "base64-js": "^1.0.2", 75 | "ieee754": "^1.1.4" 76 | } 77 | }, 78 | "buffer-xor": { 79 | "version": "1.0.3", 80 | "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", 81 | "integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=" 82 | }, 83 | "bytebuffer": { 84 | "version": "5.0.1", 85 | "resolved": "https://registry.npmjs.org/bytebuffer/-/bytebuffer-5.0.1.tgz", 86 | "integrity": "sha1-WC7qSxqHO20CCkjVjfhfC7ps/d0=", 87 | "requires": { 88 | "long": "~3" 89 | } 90 | }, 91 | "cipher-base": { 92 | "version": "1.0.4", 93 | "resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz", 94 | "integrity": "sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q==", 95 | "requires": { 96 | "inherits": "^2.0.1", 97 | "safe-buffer": "^5.0.1" 98 | } 99 | }, 100 | "create-hash": { 101 | "version": "1.2.0", 102 | "resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", 103 | "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==", 104 | "requires": { 105 | "cipher-base": "^1.0.1", 106 | "inherits": "^2.0.1", 107 | "md5.js": "^1.3.4", 108 | "ripemd160": "^2.0.1", 109 | "sha.js": "^2.4.0" 110 | } 111 | }, 112 | "create-hmac": { 113 | "version": "1.1.7", 114 | "resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz", 115 | "integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==", 116 | "requires": { 117 | "cipher-base": "^1.0.3", 118 | "create-hash": "^1.1.0", 119 | "inherits": "^2.0.1", 120 | "ripemd160": "^2.0.0", 121 | "safe-buffer": "^5.0.1", 122 | "sha.js": "^2.4.8" 123 | } 124 | }, 125 | "cross-env": { 126 | "version": "5.2.1", 127 | "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-5.2.1.tgz", 128 | "integrity": "sha512-1yHhtcfAd1r4nwQgknowuUNfIT9E8dOMMspC36g45dN+iD1blloi7xp8X/xAIDnjHWyt1uQ8PHk2fkNaym7soQ==", 129 | "requires": { 130 | "cross-spawn": "^6.0.5" 131 | } 132 | }, 133 | "cross-fetch": { 134 | "version": "1.1.1", 135 | "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-1.1.1.tgz", 136 | "integrity": "sha512-+VJE04+UfxxmBfcnmAu/lKor53RUCx/1ilOti4p+JgrnLQ4AZZIRoe2OEd76VaHyWQmQxqKnV+TaqjHC4r0HWw==", 137 | "requires": { 138 | "node-fetch": "1.7.3", 139 | "whatwg-fetch": "2.0.3" 140 | } 141 | }, 142 | "cross-spawn": { 143 | "version": "6.0.5", 144 | "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", 145 | "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", 146 | "requires": { 147 | "nice-try": "^1.0.4", 148 | "path-key": "^2.0.1", 149 | "semver": "^5.5.0", 150 | "shebang-command": "^1.2.0", 151 | "which": "^1.2.9" 152 | } 153 | }, 154 | "debug": { 155 | "version": "2.6.9", 156 | "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", 157 | "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", 158 | "requires": { 159 | "ms": "2.0.0" 160 | } 161 | }, 162 | "detect-node": { 163 | "version": "2.0.4", 164 | "resolved": "https://registry.npmjs.org/detect-node/-/detect-node-2.0.4.tgz", 165 | "integrity": "sha512-ZIzRpLJrOj7jjP2miAtgqIfmzbxa4ZOr5jJc601zklsfEx9oTzmmj2nVpIPRpNlRTIh8lc1kyViIY7BWSGNmKw==" 166 | }, 167 | "ecurve": { 168 | "version": "1.0.6", 169 | "resolved": "https://registry.npmjs.org/ecurve/-/ecurve-1.0.6.tgz", 170 | "integrity": "sha512-/BzEjNfiSuB7jIWKcS/z8FK9jNjmEWvUV2YZ4RLSmcDtP7Lq0m6FvDuSnJpBlDpGRpfRQeTLGLBI8H+kEv0r+w==", 171 | "requires": { 172 | "bigi": "^1.1.0", 173 | "safe-buffer": "^5.0.1" 174 | } 175 | }, 176 | "encoding": { 177 | "version": "0.1.12", 178 | "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz", 179 | "integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=", 180 | "requires": { 181 | "iconv-lite": "~0.4.13" 182 | } 183 | }, 184 | "evp_bytestokey": { 185 | "version": "1.0.3", 186 | "resolved": "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz", 187 | "integrity": "sha512-/f2Go4TognH/KvCISP7OUsHn85hT9nUkxxA9BEWxFn+Oj9o8ZNLm/40hdlgSLyuOimsrTKLUMEorQexp/aPQeA==", 188 | "requires": { 189 | "md5.js": "^1.3.4", 190 | "safe-buffer": "^5.1.1" 191 | } 192 | }, 193 | "hash-base": { 194 | "version": "3.0.4", 195 | "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.0.4.tgz", 196 | "integrity": "sha1-X8hoaEfs1zSZQDMZprCj8/auSRg=", 197 | "requires": { 198 | "inherits": "^2.0.1", 199 | "safe-buffer": "^5.0.1" 200 | } 201 | }, 202 | "iconv-lite": { 203 | "version": "0.4.24", 204 | "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", 205 | "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", 206 | "requires": { 207 | "safer-buffer": ">= 2.1.2 < 3" 208 | } 209 | }, 210 | "ieee754": { 211 | "version": "1.1.13", 212 | "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", 213 | "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" 214 | }, 215 | "inherits": { 216 | "version": "2.0.4", 217 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", 218 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" 219 | }, 220 | "is-stream": { 221 | "version": "1.1.0", 222 | "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", 223 | "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" 224 | }, 225 | "isexe": { 226 | "version": "2.0.0", 227 | "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", 228 | "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" 229 | }, 230 | "lodash": { 231 | "version": "4.17.15", 232 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", 233 | "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" 234 | }, 235 | "long": { 236 | "version": "3.2.0", 237 | "resolved": "https://registry.npmjs.org/long/-/long-3.2.0.tgz", 238 | "integrity": "sha1-2CG3E4yhy1gcFymQ7xTbIAtcR0s=" 239 | }, 240 | "md5.js": { 241 | "version": "1.3.5", 242 | "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz", 243 | "integrity": "sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==", 244 | "requires": { 245 | "hash-base": "^3.0.0", 246 | "inherits": "^2.0.1", 247 | "safe-buffer": "^5.1.2" 248 | } 249 | }, 250 | "ms": { 251 | "version": "2.0.0", 252 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 253 | "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" 254 | }, 255 | "nice-try": { 256 | "version": "1.0.5", 257 | "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", 258 | "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==" 259 | }, 260 | "node-fetch": { 261 | "version": "1.7.3", 262 | "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", 263 | "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", 264 | "requires": { 265 | "encoding": "^0.1.11", 266 | "is-stream": "^1.0.1" 267 | } 268 | }, 269 | "path-key": { 270 | "version": "2.0.1", 271 | "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", 272 | "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=" 273 | }, 274 | "retry": { 275 | "version": "0.12.0", 276 | "resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz", 277 | "integrity": "sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs=" 278 | }, 279 | "ripemd160": { 280 | "version": "2.0.2", 281 | "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz", 282 | "integrity": "sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==", 283 | "requires": { 284 | "hash-base": "^3.0.0", 285 | "inherits": "^2.0.1" 286 | } 287 | }, 288 | "safe-buffer": { 289 | "version": "5.2.0", 290 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz", 291 | "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==" 292 | }, 293 | "safer-buffer": { 294 | "version": "2.1.2", 295 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", 296 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" 297 | }, 298 | "secure-random": { 299 | "version": "1.1.2", 300 | "resolved": "https://registry.npmjs.org/secure-random/-/secure-random-1.1.2.tgz", 301 | "integrity": "sha512-H2bdSKERKdBV1SwoqYm6C0y+9EA94v6SUBOWO8kDndc4NoUih7Dv6Tsgma7zO1lv27wIvjlD0ZpMQk7um5dheQ==" 302 | }, 303 | "semver": { 304 | "version": "5.7.1", 305 | "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", 306 | "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" 307 | }, 308 | "sha.js": { 309 | "version": "2.4.11", 310 | "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", 311 | "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", 312 | "requires": { 313 | "inherits": "^2.0.1", 314 | "safe-buffer": "^5.0.1" 315 | } 316 | }, 317 | "shebang-command": { 318 | "version": "1.2.0", 319 | "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", 320 | "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", 321 | "requires": { 322 | "shebang-regex": "^1.0.0" 323 | } 324 | }, 325 | "shebang-regex": { 326 | "version": "1.0.0", 327 | "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", 328 | "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=" 329 | }, 330 | "steem": { 331 | "version": "0.7.9", 332 | "resolved": "https://registry.npmjs.org/steem/-/steem-0.7.9.tgz", 333 | "integrity": "sha512-ALD6Ij8zBdw3fdgbdXGHsqGUUGOba/S/uJXH24keoOAQ+0GbbsiNqooVQ9YtZNLnjYFkq8mVim+puaFubB7vnQ==", 334 | "requires": { 335 | "@steemit/rpc-auth": "^1.1.1", 336 | "bigi": "^1.4.2", 337 | "bluebird": "^3.4.6", 338 | "browserify-aes": "^1.0.6", 339 | "bs58": "^4.0.0", 340 | "buffer": "^5.0.6", 341 | "bytebuffer": "^5.0.1", 342 | "create-hash": "^1.1.2", 343 | "create-hmac": "^1.1.4", 344 | "cross-env": "^5.0.0", 345 | "cross-fetch": "^1.1.1", 346 | "debug": "^2.6.8", 347 | "detect-node": "^2.0.3", 348 | "ecurve": "^1.0.5", 349 | "lodash": "^4.16.4", 350 | "retry": "^0.12.0", 351 | "secure-random": "^1.1.2", 352 | "ws": "^3.3.2" 353 | } 354 | }, 355 | "ultron": { 356 | "version": "1.1.1", 357 | "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz", 358 | "integrity": "sha512-UIEXBNeYmKptWH6z8ZnqTeS8fV74zG0/eRU9VGkpzz+LIJNs8W/zM/L+7ctCkRrgbNnnR0xxw4bKOr0cW0N0Og==" 359 | }, 360 | "whatwg-fetch": { 361 | "version": "2.0.3", 362 | "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz", 363 | "integrity": "sha1-nITsLc9oGH/wC8ZOEnS0QhduHIQ=" 364 | }, 365 | "which": { 366 | "version": "1.3.1", 367 | "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", 368 | "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", 369 | "requires": { 370 | "isexe": "^2.0.0" 371 | } 372 | }, 373 | "ws": { 374 | "version": "3.3.3", 375 | "resolved": "https://registry.npmjs.org/ws/-/ws-3.3.3.tgz", 376 | "integrity": "sha512-nnWLa/NwZSt4KQJu51MYlCcSQ5g7INpOrOMt4XV8j4dqTXdmlUmSHQ8/oLC069ckre0fRsgfvsKwbTdtKLCDkA==", 377 | "requires": { 378 | "async-limiter": "~1.0.0", 379 | "safe-buffer": "~5.1.0", 380 | "ultron": "~1.1.0" 381 | }, 382 | "dependencies": { 383 | "safe-buffer": { 384 | "version": "5.1.2", 385 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", 386 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" 387 | } 388 | } 389 | } 390 | } 391 | } 392 | -------------------------------------------------------------------------------- /steemjs/account_update2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "account_update2", 3 | "version": "1.0.0", 4 | "description": "Updates posting_json_metadata using posting key", 5 | "main": "account_update2.js", 6 | "dependencies": { 7 | "steem": "^0.7.9" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees (http://steemit.com/@howo)", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/comment/comment.js: -------------------------------------------------------------------------------- 1 | var steem = require('steem'); 2 | steem.api.setOptions({url: 'https://api.steemit.com'}); 3 | /** 4 | * Posts a comment on an already existing article 5 | * @param {String} username - username of the account 6 | * @param {String} password - password of the account 7 | * @param {String} author - Author of the post to comment to 8 | * @param {String} permlink - permanent link of the post to comment to. eg : https://steemit.com/programming/@howo/introducting-steemsnippets the permlink is "introducting-steemsnippets" 9 | * @param {String} text - Content of the comment. 10 | * @param {object} [jsonMetadata] - dictionnary with additional tags, app name, etc, 11 | */ 12 | function comment(username, password, author, permlink, text, jsonMetadata) { 13 | var wif = steem.auth.toWif(username, password, 'posting'); 14 | jsonMetadata = jsonMetadata || {}; 15 | var comment_permlink = new Date().toISOString().replace(/[^a-zA-Z0-9]+/g, '').toLowerCase(); 16 | 17 | steem.broadcast.comment(wif, author, permlink, username, comment_permlink , '', text, jsonMetadata, function(err, result) { 18 | console.log(err, result); 19 | }); 20 | } 21 | 22 | // example 23 | comment("username", "password", "howo", "introducting-steemsnippets", 'Woah nice article'); 24 | 25 | -------------------------------------------------------------------------------- /steemjs/comment/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "comment", 3 | "version": "1.0.0", 4 | "description": "Comments on an article on the steem blockchain", 5 | "main": "comment.js", 6 | "dependencies": { 7 | "steem": "^0.6.7" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/create_account/create_account.js: -------------------------------------------------------------------------------- 1 | var steem = require('steem'); 2 | steem.api.setOptions({url: 'https://api.steemit.com'}); 3 | var Asset = require('dsteem').Asset; 4 | 5 | var testnet = true; // set to true if you want to use the testnet, false for the main net 6 | 7 | if (testnet) 8 | { 9 | steem.api.setOptions({ url: 'wss://testnet.steem.vc',address_prefix:'STX',chain_id: '79276aea5d4877d9a25892eaa01b0adf019d3e5cb12a97478df3298ccdd01673' }); 10 | steem.config.set('websocket','wss://testnet.steem.vc') 11 | steem.config.set('address_prefix', 'STX') 12 | steem.config.set('chain_id', '79276aea5d4877d9a25892eaa01b0adf019d3e5cb12a97478df3298ccdd01673') 13 | } 14 | /* 15 | 16 | Example on how to use the function : 17 | 18 | var wif = steem.auth.toWif("how", "barman", 'active'); 19 | createAccount("newaccount", "newaccountpassword", "how", wif, function (success) { 20 | console.log(success) 21 | }); 22 | */ 23 | 24 | /** 25 | * Creates an account, note that almost no validation is done. 26 | * @param {String} username - username of the new account 27 | * @param {String} password - password of the new account 28 | * @param {String} owner_name - Name of the account that will pay the fee (and create the account). 29 | * @param {String} wif - active key of the account that will pay the fee (and create the account). 30 | * @param {callback} callback - callback with a boolean containing whether the account creation was successfull or not. 31 | */ 32 | function createAccount(username, password, owner_name, wif, callback) 33 | { 34 | 35 | // Generate the keypairs 36 | var publicKeys = steem.auth.generateKeys(username, password, ['posting', 'owner', 'active', 'memo']); 37 | 38 | // Create the key objects 39 | var owner = { 40 | weight_threshold: 1, 41 | account_auths: [], 42 | key_auths: [[publicKeys.owner, 1]] 43 | }; 44 | var active = { 45 | weight_threshold: 1, 46 | account_auths: [], 47 | key_auths: [[publicKeys.active, 1]] 48 | }; 49 | var posting = { 50 | weight_threshold: 1, 51 | account_auths: [], 52 | key_auths: [[publicKeys.posting, 1]] 53 | }; 54 | 55 | 56 | // Get the the steem blockchain configuration 57 | steem.api.getConfig(function(err, config) { 58 | if (err) { 59 | console.log(err, config); 60 | throw new Error(err); 61 | } 62 | // Get the steem blockchain properties 63 | steem.api.getChainProperties(function (err2, chainProps) { 64 | if (err2) { 65 | console.log(err2, chainProps); 66 | throw new Error(err2); 67 | } 68 | 69 | // Get the ratio to create an account without delegation, as of writing this it's 3. 70 | var ratio = config['STEEMIT_CREATE_ACCOUNT_WITH_STEEM_MODIFIER']; 71 | // Get the account creation fee and multiply it by the ratio to get the fee needed to create an account without delegation 72 | var fee = Asset.from(chainProps.account_creation_fee).multiply(ratio); 73 | // Get the fee in the format for accountCreate aka "X.XXX STEEM" 74 | var feeString = fee.toString(); 75 | 76 | var jsonMetadata = ''; 77 | var success = false; 78 | try { 79 | steem.broadcast.accountCreate(wif, feeString, owner_name, 80 | username, owner, active, posting, publicKeys.memo, 81 | jsonMetadata, function (err) { 82 | if (err == null) 83 | success = true; 84 | callback(success) 85 | }); 86 | } catch(e) { 87 | console.log(e) 88 | } 89 | }); 90 | }); 91 | 92 | } 93 | 94 | -------------------------------------------------------------------------------- /steemjs/create_account/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "create_account", 3 | "version": "1.0.0", 4 | "description": "How to create an account", 5 | "main": "create_account.js", 6 | "dependencies": { 7 | "dsteem": "^0.8.6", 8 | "steem": "^0.6.7" 9 | }, 10 | "devDependencies": {}, 11 | "scripts": { 12 | "test": "echo \"Error: no test specified\" && exit 1" 13 | }, 14 | "author": "Martin Lees", 15 | "license": "MIT" 16 | } 17 | -------------------------------------------------------------------------------- /steemjs/downvoting_power/downvoting_power.js: -------------------------------------------------------------------------------- 1 | var steem = require('steem'); 2 | steem.api.setOptions({url: 'https://api.steemit.com'}); 3 | /** 4 | * Gets the downvoting power of an account. 5 | * @param {String} account_name - account of whom we want to check the downvoting power 6 | */ 7 | function get_downvoting_power(account_name) { 8 | return new Promise(resolve => { 9 | steem.api.getAccounts([account_name], function (err, account) { 10 | 11 | account = account[0]; 12 | 13 | const totalShares = parseFloat(account.vesting_shares) + parseFloat(account.received_vesting_shares) - parseFloat(account.delegated_vesting_shares) - parseFloat(account.vesting_withdraw_rate); 14 | 15 | const elapsed = Math.floor(Date.now() / 1000) - account.downvote_manabar.last_update_time; 16 | const maxMana = totalShares * 1000000 / 4; 17 | // 432000 sec = 5 days 18 | let currentMana = parseFloat(account.downvote_manabar.current_mana) + elapsed * maxMana / 432000; 19 | 20 | if (currentMana > maxMana) { 21 | currentMana = maxMana; 22 | } 23 | 24 | const currentManaPerc = currentMana * 100 / maxMana; 25 | 26 | return resolve(currentManaPerc); 27 | }); 28 | }); 29 | } 30 | 31 | 32 | async function example() 33 | { 34 | const vp = await get_downvoting_power("howo"); 35 | console.log(vp); 36 | } 37 | 38 | example(); -------------------------------------------------------------------------------- /steemjs/downvoting_power/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "downvoting_power", 3 | "version": "1.0.0", 4 | "description": "Gets the downvoting power of an user", 5 | "main": "downvoting_power.js", 6 | "dependencies": { 7 | "steem": "^0.6.7" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/get_active_votes/get_active_votes.js: -------------------------------------------------------------------------------- 1 | var steem = require('steem'); 2 | steem.api.setOptions({url: 'https://api.steemit.com'}); 3 | 4 | 5 | /* 6 | ====================================================================================================================== 7 | ====================================================================================================================== 8 | ====================================================================================================================== 9 | ====================================================================================================================== 10 | ====================================================================================================================== 11 | ====================================================================================================================== 12 | ====================================================================================================================== 13 | getAccountVotes is probably already deprecated and this snippet is no longer working. I suggest looking at the 14 | get_active_votes in the dsteem folder. 15 | ====================================================================================================================== 16 | ====================================================================================================================== 17 | ====================================================================================================================== 18 | ====================================================================================================================== 19 | ====================================================================================================================== 20 | ====================================================================================================================== 21 | ====================================================================================================================== 22 | ====================================================================================================================== 23 | */ 24 | 25 | /** 26 | * Checks if a post is awaiting payout 27 | * @param {string} author - Username of the user who created the post 28 | * @param {string} permlink - permlink of the post 29 | */ 30 | function is_post_active(author, permlink) 31 | { 32 | return new Promise(resolve => { 33 | var _7_days_ago = Math.floor(new Date().getTime() / 1000) - 86400 * 7; 34 | steem.api.getContent(author, permlink, function (err, post_result) { 35 | 36 | var created_date = Math.floor(Date.parse(post_result['created']) / 1000); 37 | 38 | if (created_date - _7_days_ago > 0) { 39 | resolve(true) 40 | } else { 41 | resolve(false) 42 | } 43 | }); 44 | }); 45 | } 46 | 47 | /** 48 | * Gets the votes from an user on posts that are still awaiting payout 49 | * @param {string} username - Username of the user from which to get the active votes 50 | */ 51 | function get_active_votes(username) 52 | { 53 | return new Promise( resolve => { 54 | var _7_days_ago = Math.floor(new Date().getTime() / 1000) - 86400 * 7; 55 | var active_votes = []; 56 | 57 | steem.api.getAccountVotes(username,async function (error, result) { 58 | 59 | for (var i = 0; i < result.length; i++) { 60 | 61 | var post_time = Math.floor(Date.parse(result[i]['time']) / 1000); 62 | 63 | if (post_time - _7_days_ago > 0) { 64 | 65 | var author = result[i]['authorperm'].substring(0, result[i]['authorperm'].indexOf("/")); 66 | var permlink = result[i]['authorperm'].substring(result[i]['authorperm'].indexOf("/")+1); 67 | 68 | var active = await is_post_active(author, permlink); 69 | 70 | if (active) 71 | active_votes.push(result[i]) 72 | } 73 | } 74 | resolve(active_votes); 75 | }); 76 | }); 77 | 78 | } 79 | 80 | // example 81 | // if you get error, make sure that you have the latest node version. 82 | async function main() { 83 | var active_votes = await get_active_votes("jesta"); 84 | console.log(active_votes); 85 | } 86 | 87 | main() 88 | -------------------------------------------------------------------------------- /steemjs/get_active_votes/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "get_active_votes", 3 | "version": "1.0.0", 4 | "description": "Gets the votes from an user on posts that are still awaiting payout", 5 | "main": "get_active_votes.js", 6 | "dependencies": { 7 | "steem": "^0.6.7" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees (http://steemit.com/@howo)", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/get_all_comments/get_all_comments.js: -------------------------------------------------------------------------------- 1 | var steem = require('steem'); 2 | steem.api.setOptions({url: 'https://api.steemit.com'}); 3 | //================================================================================ 4 | //================================================================================ 5 | //================================================================================ 6 | //================================================================================ 7 | //================================================================================ 8 | //================================================================================ 9 | //================================================================================ 10 | //================================================================================ 11 | //================================================================================ 12 | //================================================================================ 13 | //================================================================================ 14 | // GET_STATE IS DEPRECATED, THIS SNIPPET PROBABLY DOESNT WORK NOW 15 | // Please check out https://github.com/drov0/steemsnippets/tree/master/dsteem/get_all_comments instead 16 | //================================================================================ 17 | //================================================================================ 18 | //================================================================================ 19 | //================================================================================ 20 | //================================================================================ 21 | //================================================================================ 22 | //================================================================================ 23 | //================================================================================ 24 | //================================================================================ 25 | //================================================================================ 26 | //================================================================================ 27 | //================================================================================ 28 | //================================================================================ 29 | 30 | 31 | /** 32 | * 33 | * From a comment (username and permlink) get the original post(username and permlink) on which it was done 34 | * @param {String} author - username of the author 35 | * @param {String} permlink - permlink of the post 36 | * @param {String} tag - primary tag of the post 37 | * 38 | * @return {Object} an object with all the comments ordered 39 | */ 40 | function get_all_comments(author, permlink, tag) 41 | { 42 | return new Promise(resolve => { 43 | steem.api.getState(tag+"/@"+author+"/"+permlink, async function (err, post) { 44 | if (err) 45 | return resolve({error:err}); 46 | 47 | if (post['root_permlink'] === "" && post['root_author'] === "" ) 48 | return resolve({error:"content not found"}); 49 | 50 | let comment_list = post.content; 51 | let comments_ordered = []; 52 | // remove the post itself 53 | //delete comment_list[author+"/"+permlink]; 54 | 55 | for (const comment_id in comment_list) { 56 | 57 | let comment = comment_list[comment_id]; 58 | 59 | if (comment.depth !== 0) 60 | continue; 61 | comments_ordered.push(get_replies(comment, comment_list)); 62 | } 63 | 64 | return resolve(comments_ordered); 65 | }); 66 | }); 67 | } 68 | 69 | function get_replies(comment, comment_list) 70 | { 71 | for (let i = 0; i < comment.replies.length; i++) { 72 | let reply = comment_list[comment.replies[i]]; 73 | comment.replies[i] = get_replies(reply, comment_list); 74 | } 75 | return comment; 76 | } 77 | 78 | 79 | // Replies objects are located in the "replies" field. 80 | async function example() 81 | { 82 | let data = await get_all_comments("petanque", "testcomments-xylmwuwi6p", "steempress"); 83 | console.log(data); 84 | } 85 | 86 | 87 | example(); 88 | -------------------------------------------------------------------------------- /steemjs/get_all_comments/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "get_all_comments", 3 | "version": "1.0.0", 4 | "description": "Get All the replies from a post.", 5 | "main": "get_all_comments.js", 6 | "dependencies": { 7 | "steem": "^0.6.7" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/get_followers_following/get_followers_following.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Gets the number of followers and number of followed accounts. 4 | * @param {String} username - username of the account 5 | @returns {Promise.} Oject containing the number of followers and number of follows 6 | @fulfils {int} followers - number of followers 7 | @fulfils {int} following - Number of users the account is following. 8 | */ 9 | 10 | function get_followers_following(username) { 11 | var steem = require('steem'); 12 | steem.api.setOptions({url: 'https://api.steemit.com'}); 13 | 14 | return new Promise(resolve => { 15 | 16 | steem.api.getFollowCount(username, function (err, follow_data) { 17 | if (err) { 18 | console.log(err); 19 | return resolve(get_followers_following(username)); // in case of an rpc error, we call the function recursively 20 | } 21 | 22 | const followers = follow_data.follower_count; 23 | const following = follow_data.following_count; 24 | 25 | resolve({"followers":followers, "following":following}); 26 | 27 | }); 28 | }); 29 | } 30 | 31 | 32 | // example 33 | 34 | // Note : if you have errors with the await, make sure your node is up to date to support ES6. 35 | 36 | async function example() 37 | { 38 | const data = await get_followers_following("howo"); 39 | console.log("howo has "+ data.followers + " followers and he's following "+ data.following + " users. ") 40 | } 41 | 42 | 43 | example(); 44 | -------------------------------------------------------------------------------- /steemjs/get_followers_following/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "get_followers_following", 3 | "version": "1.0.0", 4 | "description": "Gets number of followers and number of followed accounts", 5 | "main": "get_followers_following.js", 6 | "dependencies": { 7 | "steem": "^0.6.7" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees (http://steemit.com/@howo)", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/get_new_posts/get_new_posts.js: -------------------------------------------------------------------------------- 1 | var steem = require('steem'); 2 | steem.api.setOptions({url: 'https://api.steemit.com'}); 3 | /** 4 | * This function will be called when a call to steem api is complete 5 | * @callback newPostsCallback 6 | * @param {Object} err - an object describing any error encountered 7 | * @param {Array} response - an array of posts 8 | */ 9 | 10 | /** 11 | * Gets the latest posts 12 | * @param {Object} query - an object specifying which posts to get 13 | * @param {string} query.[tag] - the tag for which to get posts 14 | * @param {string} query.[limit] - the maximmum number of posts to get 15 | * @param {newPostsCallback} callback - function which will receive the array of posts as a parameter 16 | */ 17 | function getNewPosts(query, callback){ 18 | steem.api.getDiscussionsByCreated(query, function(err, response){ 19 | var result = []; 20 | if(!err) result = response; 21 | callback(result); 22 | }); 23 | } 24 | 25 | //example - gets the most recent post in tag 'life' 26 | getNewPosts({tag:"life", limit:1}, function(latestPost) { 27 | console.log(latestPost[0].title, latestPost[0].author); 28 | }); 29 | -------------------------------------------------------------------------------- /steemjs/get_new_posts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "get_new_posts", 3 | "version": "1.0.0", 4 | "description": "How to get new posts", 5 | "main": "get_new_posts.js", 6 | "dependencies": { 7 | "steem": "^0.6.7" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Trevor Reid (http://steemit.com/@tdre)", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/get_reputation/get_reputation.js: -------------------------------------------------------------------------------- 1 | var steem = require('steem'); 2 | steem.api.setOptions({url: 'https://api.steemit.com'}); 3 | 4 | /** 5 | * From a comment (username and permlink) get the original post(username and permlink) on which it was done 6 | * @param {String} username - username of the author 7 | * 8 | * @return {Object} an object with the simplified and raw reputation 9 | */ 10 | function get_reputation(username) 11 | { 12 | return new Promise(resolve => { 13 | 14 | steem.api.getAccounts([username], function (err, account) { 15 | if (err) { 16 | console.log(err); 17 | return resolve({error : err}); 18 | } 19 | 20 | if (account.length === 0) 21 | return resolve({error : "Account doesn't exist"}); 22 | 23 | const simplified_reputation = steem.formatter.reputation(account[0].reputation); 24 | 25 | resolve({simplified_reputation : simplified_reputation, raw_reputation : account[0].reputation}); 26 | 27 | }); 28 | }); 29 | } 30 | 31 | 32 | // example 33 | async function example() 34 | { 35 | // working example 36 | let data = await get_reputation("howo"); 37 | console.log(data); // { simplified_reputation: 63, raw_reputation: '17178492578569' } 38 | 39 | // account that doesn't exist 40 | data = await get_reputation("a"); 41 | console.log(data) // { error: 'Account doesn't exist' } 42 | } 43 | 44 | 45 | example(); 46 | 47 | -------------------------------------------------------------------------------- /steemjs/get_reputation/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "get_reputation", 3 | "version": "1.0.0", 4 | "description": "Get the simplified and raw reputation of an user", 5 | "main": "get_reputation.js", 6 | "dependencies": { 7 | "steem": "^0.6.7" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/get_root_post/get_root_post.js: -------------------------------------------------------------------------------- 1 | var steem = require('steem'); 2 | steem.api.setOptions({url: 'https://api.steemit.com'}); 3 | 4 | /** 5 | * From a comment (username and permlink) get the original post(username and permlink) on which it was done 6 | * @param {String} author - username of the author 7 | * @param {String} permlink - permlink of the post 8 | * 9 | * @return {Object} an object with the original post permlink and author 10 | */ 11 | function get_root_post(author, permlink) 12 | { 13 | return new Promise(resolve => { 14 | steem.api.getContent(author, permlink, async function (err, post) { 15 | if (err) 16 | return resolve({error:err}); 17 | 18 | if (post['root_permlink'] === "" && post['root_author'] === "" ) 19 | return resolve({error:"content not found"}); 20 | 21 | return resolve({"root_permlink":post['root_permlink'], "root_author": post['root_author']}); 22 | }); 23 | }); 24 | } 25 | 26 | // example 27 | async function example() 28 | { 29 | // working example 30 | let data = await get_root_post("howo", "re-pixelhosting-pixelhosting-by-wehmoen-free-image-hosting-for-steem-projects-20180422t001219308z"); 31 | console.log(data); // { root_permlink: 'pixelhosting-by-wehmoen-free-image-hosting-for-steem-projects', root_author: 'pixelhosting' } 32 | 33 | // comment that doesn't exist 34 | data = await get_root_post("howo", "re-pixeddddlhosting-pixelhosting-by-wehmoen-free-image-hosting-for-steem-projects-20180422t001219308z"); 35 | console.log(data) // { error: 'content not found' } 36 | } 37 | 38 | 39 | example(); 40 | 41 | -------------------------------------------------------------------------------- /steemjs/get_root_post/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "get_root_post", 3 | "version": "1.0.0", 4 | "description": "From a comment (username and permlink) get the original post(username and permlink) on which it was done", 5 | "main": "get_root_post.js", 6 | "dependencies": { 7 | "steem": "^0.6.7" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/get_steem_power/get_steem_power.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Gets the steem power of an account 3 | * @param {String} username - username of the account 4 | @returns {Promise.} Oject containing the steem power and delegated steem power 5 | @fulfils {float} steem_power - steem power of the user (without taking into account the delegations) 6 | @fulfils {float} delegated_steem_power - delegated steem power to/from the user this can go negative if it's a delegation that is sent. 7 | */ 8 | function get_steem_power(username) { 9 | 10 | const steem = require('steem'); 11 | steem.api.setOptions({url: 'https://api.steemit.com'}); 12 | 13 | return new Promise(resolve => { 14 | steem.api.getAccounts([username], function (err, account) { 15 | if (err) { 16 | console.log(err) 17 | return resolve(get_steem_power(username)); // recursion in case of rpc error. 18 | } 19 | var vesting_shares, delegated_vesting_shares, received_vesting_shares, total_vesting_shares = null; 20 | vesting_shares = account[0].vesting_shares; 21 | delegated_vesting_shares = account[0].delegated_vesting_shares; 22 | received_vesting_shares = account[0].received_vesting_shares; 23 | 24 | steem.api.getDynamicGlobalProperties(function (err, properties) { 25 | if (err) { 26 | console.log(err) 27 | return resolve(get_steem_power(username)); // recursion in case of rpc error. 28 | } 29 | 30 | total_vesting_shares = properties.total_vesting_shares; 31 | let total_vesting_fund = properties.total_vesting_fund_steem; 32 | 33 | // Handle Promises, when you’re sure the two functions were completed simply do: 34 | var steem_power = steem.formatter.vestToSteem(vesting_shares, total_vesting_shares, total_vesting_fund); 35 | var delegated_steem_power = steem.formatter.vestToSteem((received_vesting_shares.split(' ')[0] - delegated_vesting_shares.split(' ')[0]) + ' VESTS', total_vesting_shares, total_vesting_fund); 36 | 37 | steem_power = Math.floor(steem_power*1000)/1000; 38 | delegated_steem_power = Math.floor(delegated_steem_power*1000)/1000; 39 | 40 | resolve({"steem_power" : steem_power, "delegated_steem_power" : delegated_steem_power}); 41 | }); 42 | }); 43 | }); 44 | } 45 | 46 | 47 | // example 48 | async function example() 49 | { 50 | const data = await get_steem_power("howo"); 51 | console.log("howo has "+ data.steem_power + " steem power and has "+ data.delegated_steem_power + " delegated steem power, so his current steem power is " + (data.steem_power+data.delegated_steem_power)) 52 | } 53 | 54 | 55 | example() 56 | -------------------------------------------------------------------------------- /steemjs/get_steem_power/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "get_steem_power", 3 | "version": "1.0.0", 4 | "description": "Get the steem power of an account", 5 | "main": "get_steem_power.js", 6 | "dependencies": { 7 | "steem": "^0.6.7" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees (http://steemit.com/@howo)", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/post/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "post", 3 | "version": "1.0.0", 4 | "description": "Posts an article to the steem blockchain", 5 | "main": "post.js", 6 | "dependencies": { 7 | "steem": "^0.6.7" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/post/post.js: -------------------------------------------------------------------------------- 1 | var steem = require('steem'); 2 | steem.api.setOptions({url: 'https://api.steemit.com'}); 3 | /** 4 | * Posts an article to the steem blockchain 5 | * @param {String} username - username of the account 6 | * @param {String} postingkey - private posting key of the account 7 | * @param {String} main_tag - The main tag for the post 8 | * @param {String} title - Title of the post 9 | * @param {String} body - body (content) of the post. 10 | * @param {object} [jsonMetadata] - dictionnary with additional tags, app name, etc, 11 | * @param {String} [permlink] - permanent link, by default it's the date + -post. eg : 20171237t122520625z-post 12 | */ 13 | function post(username, postingkey, main_tag, title, body, jsonMetadata, permlink) { 14 | // By default permlink will be the date 15 | permlink = permlink || new Date().toISOString().replace(/[^a-zA-Z0-9]+/g, '').toLowerCase(); 16 | jsonMetadata = jsonMetadata || {}; 17 | 18 | steem.broadcast.comment(postingkey, '', main_tag, username, permlink + '-post', title, body, jsonMetadata, function (err, result) { 19 | console.log(err, result); 20 | }); 21 | } 22 | // example 23 | post("username", "password", "tag1", "title", "body", { tags: ['tag2', 'tag3']}); 24 | 25 | -------------------------------------------------------------------------------- /steemjs/post_exists/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "get_new_posts", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "async-limiter": { 8 | "version": "1.0.0", 9 | "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", 10 | "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==" 11 | }, 12 | "base-x": { 13 | "version": "3.0.4", 14 | "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.4.tgz", 15 | "integrity": "sha512-UYOadoSIkEI/VrRGSG6qp93rp2WdokiAiNYDfGW5qURAY8GiAQkvMbwNNSDYiVJopqv4gCna7xqf4rrNGp+5AA==", 16 | "requires": { 17 | "safe-buffer": "5.1.1" 18 | } 19 | }, 20 | "base64-js": { 21 | "version": "1.2.3", 22 | "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.2.3.tgz", 23 | "integrity": "sha512-MsAhsUW1GxCdgYSO6tAfZrNapmUKk7mWx/k5mFY/A1gBtkaCaNapTg+FExCw1r9yeaZhqx/xPg43xgTFH6KL5w==" 24 | }, 25 | "bigi": { 26 | "version": "1.4.2", 27 | "resolved": "https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz", 28 | "integrity": "sha1-nGZalfiLiwj8Bc/XMfVhhZ1yWCU=" 29 | }, 30 | "bluebird": { 31 | "version": "3.5.1", 32 | "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz", 33 | "integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==" 34 | }, 35 | "browserify-aes": { 36 | "version": "1.1.1", 37 | "resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.1.1.tgz", 38 | "integrity": "sha512-UGnTYAnB2a3YuYKIRy1/4FB2HdM866E0qC46JXvVTYKlBlZlnvfpSfY6OKfXZAkv70eJ2a1SqzpAo5CRhZGDFg==", 39 | "requires": { 40 | "buffer-xor": "1.0.3", 41 | "cipher-base": "1.0.4", 42 | "create-hash": "1.1.3", 43 | "evp_bytestokey": "1.0.3", 44 | "inherits": "2.0.3", 45 | "safe-buffer": "5.1.1" 46 | } 47 | }, 48 | "bs58": { 49 | "version": "4.0.1", 50 | "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz", 51 | "integrity": "sha1-vhYedsNU9veIrkBx9j806MTwpCo=", 52 | "requires": { 53 | "base-x": "3.0.4" 54 | } 55 | }, 56 | "buffer": { 57 | "version": "5.1.0", 58 | "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.1.0.tgz", 59 | "integrity": "sha512-YkIRgwsZwJWTnyQrsBTWefizHh+8GYj3kbL1BTiAQ/9pwpino0G7B2gp5tx/FUBqUlvtxV85KNR3mwfAtv15Yw==", 60 | "requires": { 61 | "base64-js": "1.2.3", 62 | "ieee754": "1.1.8" 63 | } 64 | }, 65 | "buffer-xor": { 66 | "version": "1.0.3", 67 | "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", 68 | "integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=" 69 | }, 70 | "bytebuffer": { 71 | "version": "5.0.1", 72 | "resolved": "https://registry.npmjs.org/bytebuffer/-/bytebuffer-5.0.1.tgz", 73 | "integrity": "sha1-WC7qSxqHO20CCkjVjfhfC7ps/d0=", 74 | "requires": { 75 | "long": "3.2.0" 76 | } 77 | }, 78 | "cipher-base": { 79 | "version": "1.0.4", 80 | "resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz", 81 | "integrity": "sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q==", 82 | "requires": { 83 | "inherits": "2.0.3", 84 | "safe-buffer": "5.1.1" 85 | } 86 | }, 87 | "create-hash": { 88 | "version": "1.1.3", 89 | "resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.1.3.tgz", 90 | "integrity": "sha1-YGBCrIuSYnUPSDyt2rD1gZFy2P0=", 91 | "requires": { 92 | "cipher-base": "1.0.4", 93 | "inherits": "2.0.3", 94 | "ripemd160": "2.0.1", 95 | "sha.js": "2.4.10" 96 | } 97 | }, 98 | "create-hmac": { 99 | "version": "1.1.6", 100 | "resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.6.tgz", 101 | "integrity": "sha1-rLniIaThe9sHbpBlfEK5PjcmzwY=", 102 | "requires": { 103 | "cipher-base": "1.0.4", 104 | "create-hash": "1.1.3", 105 | "inherits": "2.0.3", 106 | "ripemd160": "2.0.1", 107 | "safe-buffer": "5.1.1", 108 | "sha.js": "2.4.10" 109 | } 110 | }, 111 | "cross-env": { 112 | "version": "5.1.4", 113 | "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-5.1.4.tgz", 114 | "integrity": "sha512-Mx8mw6JWhfpYoEk7PGvHxJMLQwQHORAs8+2bX+C1lGQ4h3GkDb1zbzC2Nw85YH9ZQMlO0BHZxMacgrfPmMFxbg==", 115 | "requires": { 116 | "cross-spawn": "5.1.0", 117 | "is-windows": "1.0.2" 118 | } 119 | }, 120 | "cross-fetch": { 121 | "version": "1.1.1", 122 | "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-1.1.1.tgz", 123 | "integrity": "sha512-+VJE04+UfxxmBfcnmAu/lKor53RUCx/1ilOti4p+JgrnLQ4AZZIRoe2OEd76VaHyWQmQxqKnV+TaqjHC4r0HWw==", 124 | "requires": { 125 | "node-fetch": "1.7.3", 126 | "whatwg-fetch": "2.0.3" 127 | } 128 | }, 129 | "cross-spawn": { 130 | "version": "5.1.0", 131 | "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", 132 | "integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=", 133 | "requires": { 134 | "lru-cache": "4.1.2", 135 | "shebang-command": "1.2.0", 136 | "which": "1.3.0" 137 | } 138 | }, 139 | "debug": { 140 | "version": "2.6.9", 141 | "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", 142 | "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", 143 | "requires": { 144 | "ms": "2.0.0" 145 | } 146 | }, 147 | "detect-node": { 148 | "version": "2.0.3", 149 | "resolved": "https://registry.npmjs.org/detect-node/-/detect-node-2.0.3.tgz", 150 | "integrity": "sha1-ogM8CcyOFY03dI+951B4Mr1s4Sc=" 151 | }, 152 | "ecurve": { 153 | "version": "1.0.6", 154 | "resolved": "https://registry.npmjs.org/ecurve/-/ecurve-1.0.6.tgz", 155 | "integrity": "sha512-/BzEjNfiSuB7jIWKcS/z8FK9jNjmEWvUV2YZ4RLSmcDtP7Lq0m6FvDuSnJpBlDpGRpfRQeTLGLBI8H+kEv0r+w==", 156 | "requires": { 157 | "bigi": "1.4.2", 158 | "safe-buffer": "5.1.1" 159 | } 160 | }, 161 | "encoding": { 162 | "version": "0.1.12", 163 | "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz", 164 | "integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=", 165 | "requires": { 166 | "iconv-lite": "0.4.19" 167 | } 168 | }, 169 | "evp_bytestokey": { 170 | "version": "1.0.3", 171 | "resolved": "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz", 172 | "integrity": "sha512-/f2Go4TognH/KvCISP7OUsHn85hT9nUkxxA9BEWxFn+Oj9o8ZNLm/40hdlgSLyuOimsrTKLUMEorQexp/aPQeA==", 173 | "requires": { 174 | "md5.js": "1.3.4", 175 | "safe-buffer": "5.1.1" 176 | } 177 | }, 178 | "hash-base": { 179 | "version": "2.0.2", 180 | "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-2.0.2.tgz", 181 | "integrity": "sha1-ZuodhW206KVHDK32/OI65SRO8uE=", 182 | "requires": { 183 | "inherits": "2.0.3" 184 | } 185 | }, 186 | "iconv-lite": { 187 | "version": "0.4.19", 188 | "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", 189 | "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" 190 | }, 191 | "ieee754": { 192 | "version": "1.1.8", 193 | "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.8.tgz", 194 | "integrity": "sha1-vjPUCsEO8ZJnAfbwii2G+/0a0+Q=" 195 | }, 196 | "inherits": { 197 | "version": "2.0.3", 198 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", 199 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" 200 | }, 201 | "is-stream": { 202 | "version": "1.1.0", 203 | "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", 204 | "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" 205 | }, 206 | "is-windows": { 207 | "version": "1.0.2", 208 | "resolved": "https://registry.npmjs.org/is-windows/-/is-windows-1.0.2.tgz", 209 | "integrity": "sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==" 210 | }, 211 | "isexe": { 212 | "version": "2.0.0", 213 | "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", 214 | "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" 215 | }, 216 | "lodash": { 217 | "version": "4.17.5", 218 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz", 219 | "integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==" 220 | }, 221 | "long": { 222 | "version": "3.2.0", 223 | "resolved": "https://registry.npmjs.org/long/-/long-3.2.0.tgz", 224 | "integrity": "sha1-2CG3E4yhy1gcFymQ7xTbIAtcR0s=" 225 | }, 226 | "lru-cache": { 227 | "version": "4.1.2", 228 | "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.2.tgz", 229 | "integrity": "sha512-wgeVXhrDwAWnIF/yZARsFnMBtdFXOg1b8RIrhilp+0iDYN4mdQcNZElDZ0e4B64BhaxeQ5zN7PMyvu7we1kPeQ==", 230 | "requires": { 231 | "pseudomap": "1.0.2", 232 | "yallist": "2.1.2" 233 | } 234 | }, 235 | "md5.js": { 236 | "version": "1.3.4", 237 | "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.4.tgz", 238 | "integrity": "sha1-6b296UogpawYsENA/Fdk1bCdkB0=", 239 | "requires": { 240 | "hash-base": "3.0.4", 241 | "inherits": "2.0.3" 242 | }, 243 | "dependencies": { 244 | "hash-base": { 245 | "version": "3.0.4", 246 | "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.0.4.tgz", 247 | "integrity": "sha1-X8hoaEfs1zSZQDMZprCj8/auSRg=", 248 | "requires": { 249 | "inherits": "2.0.3", 250 | "safe-buffer": "5.1.1" 251 | } 252 | } 253 | } 254 | }, 255 | "ms": { 256 | "version": "2.0.0", 257 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 258 | "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" 259 | }, 260 | "node-fetch": { 261 | "version": "1.7.3", 262 | "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", 263 | "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", 264 | "requires": { 265 | "encoding": "0.1.12", 266 | "is-stream": "1.1.0" 267 | } 268 | }, 269 | "postinstall-build": { 270 | "version": "5.0.1", 271 | "resolved": "https://registry.npmjs.org/postinstall-build/-/postinstall-build-5.0.1.tgz", 272 | "integrity": "sha1-uRepB5smF42aJK9aXNjLSpkdEbk=" 273 | }, 274 | "pseudomap": { 275 | "version": "1.0.2", 276 | "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", 277 | "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=" 278 | }, 279 | "ripemd160": { 280 | "version": "2.0.1", 281 | "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.1.tgz", 282 | "integrity": "sha1-D0WEKVxTo2KK9+bXmsohzlfRxuc=", 283 | "requires": { 284 | "hash-base": "2.0.2", 285 | "inherits": "2.0.3" 286 | } 287 | }, 288 | "safe-buffer": { 289 | "version": "5.1.1", 290 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", 291 | "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" 292 | }, 293 | "secure-random": { 294 | "version": "1.1.1", 295 | "resolved": "https://registry.npmjs.org/secure-random/-/secure-random-1.1.1.tgz", 296 | "integrity": "sha1-CIDy2MUYX0vLRoQFjINrTdsHFFo=" 297 | }, 298 | "sha.js": { 299 | "version": "2.4.10", 300 | "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.10.tgz", 301 | "integrity": "sha512-vnwmrFDlOExK4Nm16J2KMWHLrp14lBrjxMxBJpu++EnsuBmpiYaM/MEs46Vxxm/4FvdP5yTwuCTO9it5FSjrqA==", 302 | "requires": { 303 | "inherits": "2.0.3", 304 | "safe-buffer": "5.1.1" 305 | } 306 | }, 307 | "shebang-command": { 308 | "version": "1.2.0", 309 | "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", 310 | "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", 311 | "requires": { 312 | "shebang-regex": "1.0.0" 313 | } 314 | }, 315 | "shebang-regex": { 316 | "version": "1.0.0", 317 | "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", 318 | "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=" 319 | }, 320 | "steem": { 321 | "version": "0.6.7", 322 | "resolved": "https://registry.npmjs.org/steem/-/steem-0.6.7.tgz", 323 | "integrity": "sha512-dUb7kLImSdgt7IEMMO2mUFZEoi3wvUtIIqpB0ayXHHBFZFgQVZhgXiRe77lbJnbpBrjBgern3u+8nt7scD1YHQ==", 324 | "requires": { 325 | "bigi": "1.4.2", 326 | "bluebird": "3.5.1", 327 | "browserify-aes": "1.1.1", 328 | "bs58": "4.0.1", 329 | "buffer": "5.1.0", 330 | "bytebuffer": "5.0.1", 331 | "create-hash": "1.1.3", 332 | "create-hmac": "1.1.6", 333 | "cross-env": "5.1.4", 334 | "cross-fetch": "1.1.1", 335 | "debug": "2.6.9", 336 | "detect-node": "2.0.3", 337 | "ecurve": "1.0.6", 338 | "lodash": "4.17.5", 339 | "postinstall-build": "5.0.1", 340 | "secure-random": "1.1.1", 341 | "ws": "3.3.3" 342 | } 343 | }, 344 | "ultron": { 345 | "version": "1.1.1", 346 | "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz", 347 | "integrity": "sha512-UIEXBNeYmKptWH6z8ZnqTeS8fV74zG0/eRU9VGkpzz+LIJNs8W/zM/L+7ctCkRrgbNnnR0xxw4bKOr0cW0N0Og==" 348 | }, 349 | "whatwg-fetch": { 350 | "version": "2.0.3", 351 | "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz", 352 | "integrity": "sha1-nITsLc9oGH/wC8ZOEnS0QhduHIQ=" 353 | }, 354 | "which": { 355 | "version": "1.3.0", 356 | "resolved": "https://registry.npmjs.org/which/-/which-1.3.0.tgz", 357 | "integrity": "sha512-xcJpopdamTuY5duC/KnTTNBraPK54YwpenP4lzxU8H91GudWpFv38u0CKjclE1Wi2EH2EDz5LRcHcKbCIzqGyg==", 358 | "requires": { 359 | "isexe": "2.0.0" 360 | } 361 | }, 362 | "ws": { 363 | "version": "3.3.3", 364 | "resolved": "https://registry.npmjs.org/ws/-/ws-3.3.3.tgz", 365 | "integrity": "sha512-nnWLa/NwZSt4KQJu51MYlCcSQ5g7INpOrOMt4XV8j4dqTXdmlUmSHQ8/oLC069ckre0fRsgfvsKwbTdtKLCDkA==", 366 | "requires": { 367 | "async-limiter": "1.0.0", 368 | "safe-buffer": "5.1.1", 369 | "ultron": "1.1.1" 370 | } 371 | }, 372 | "yallist": { 373 | "version": "2.1.2", 374 | "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", 375 | "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=" 376 | } 377 | } 378 | } 379 | -------------------------------------------------------------------------------- /steemjs/post_exists/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "post_exists", 3 | "version": "1.0.0", 4 | "description": "Checks if a vote exists or not.", 5 | "main": "post_exists.js", 6 | "dependencies": { 7 | "steem": "^0.6.7" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees (http://steemit.com/@howo)", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/post_exists/post_exists.js: -------------------------------------------------------------------------------- 1 | var steem = require('steem'); 2 | steem.api.setOptions({url: 'https://api.steemit.com'}); 3 | 4 | /** 5 | * Checks if a post exists, it's really usefull to check before trying actions on it (voting commenting etc) as people can delete their posts. 6 | * @param {string} author - Username of the user who created the post 7 | * @param {string} permlink - permlink of the post you want to check 8 | * @return {Boolean} - true if it exists, false if it doesn't 9 | */ 10 | function post_exists(author, permlink) { 11 | return new Promise(resolve => { 12 | { 13 | var steem = require('steem'); 14 | 15 | steem.api.setOptions({url: 'https://api.steemit.com'}); 16 | 17 | steem.api.getContent(author, permlink, function (err, result) { 18 | 19 | if (result['author'] === "") 20 | resolve(false); 21 | else 22 | resolve(true); 23 | }); 24 | }}) 25 | } 26 | 27 | 28 | 29 | // example 30 | // if you get error, make sure that you have the latest node version. 31 | async function main() { 32 | // this exists : https://steemit.com/utopian-io/@howo/steemsnippets-1-2-3-power-up-get-active-votes-and-get-lastest-posts-from-tags 33 | var exists = await post_exists("howo", "steemsnippets-1-2-3-power-up-get-active-votes-and-get-lastest-posts-from-tags"); 34 | console.log(exists); // true 35 | // this post does not exists 36 | var not_existing = await post_exists("howo", "nonexistant"); 37 | console.log(not_existing); // false 38 | } 39 | 40 | main() -------------------------------------------------------------------------------- /steemjs/power_up/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "power_up", 3 | "version": "1.0.0", 4 | "description": "Power up x steem to voting power", 5 | "main": "power_up.js", 6 | "dependencies": { 7 | "steem": "^0.6.7" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/power_up/power_up.js: -------------------------------------------------------------------------------- 1 | var steem = require('steem'); 2 | steem.api.setOptions({url: 'https://api.steemit.com'}); 3 | /** 4 | * Powers up tokens into STEEM Power 5 | * @param {String} username - username of the account 6 | * @param {String} Activekey - Private active key of the account 7 | * @param {String} amount - Amount of tokens that you want to power up, note that it must be written like this : x.xxx unit eg : '1.265 STEEM' or '0.010 STEEM' 8 | 9 | */ 10 | function powerup(Activekey, username, amount) { 11 | steem.broadcast.transferToVesting(Activekey, username, username, amount, function(err, result) { 12 | console.log(err, result); 13 | }); 14 | } 15 | 16 | // example : 17 | powerup("Activekey", "yourusername", "0.100 STEEM") -------------------------------------------------------------------------------- /steemjs/resteem/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "resteem", 3 | "version": "1.0.0", 4 | "description": "How to resteem a post", 5 | "main": "vote.js", 6 | "dependencies": { 7 | "steem": "^0.6.7" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/resteem/resteem.js: -------------------------------------------------------------------------------- 1 | var steem = require('steem'); 2 | steem.api.setOptions({url: 'https://api.steemit.com'}); 3 | /** 4 | * Casts a vote. 5 | * @param {String} username - username of the account resteeming 6 | * @param {String} postingkey - posting key of the account resteeming 7 | * @param {String} author - Author of the post to resteem 8 | * @param {String} permlink - permanent link of the post to resteem to. eg : https://steemit.com/programming/@howo/introducting-steemsnippets the permlink is "introducting-steemsnippets" 9 | */ 10 | function resteem(username, postingkey, author, permlink) 11 | { 12 | const json = JSON.stringify(['reblog', { 13 | account: username, 14 | author: author, 15 | permlink: permlink 16 | }]); 17 | 18 | steem.broadcast.customJson(postingkey, [], [username], 'follow', json,function (err, result) { 19 | console.log(err, result); 20 | }); 21 | } 22 | 23 | // example : resteem this post https://steemit.com/programming/@howo/introducting-steemsnippets 24 | resteem("username", "private posting key", "howo", "introducting-steemsnippets"); -------------------------------------------------------------------------------- /steemjs/simplified_rep_to_raw/simplified_rep_to_raw.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Converts a simlified reputation score (60) to it's raw form (7762471166286) 3 | * Note that this is an approximation, but it's precise enough for most of the applications. 4 | * @param {int} rep - Simplified reputation 5 | * @return {int} raw reputation 6 | */ 7 | function rep_to_raw(rep) 8 | // Convert a UI-ready rep score back into its approx raw value.""" 9 | { 10 | rep = parseFloat(rep+0.01) - 25; 11 | rep = rep / 9; 12 | rep = rep + 9; 13 | const sign = (rep >= 0 ? 1 : -1); 14 | return parseInt(sign * Math.pow(10, rep)) 15 | } 16 | 17 | // example 18 | console.log(rep_to_raw(60)); 19 | 20 | -------------------------------------------------------------------------------- /steemjs/test_login/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test_login", 3 | "version": "1.0.0", 4 | "description": "Test if a provided steem password or key is correct or not", 5 | "main": "test_login.js", 6 | "dependencies": { 7 | "steem": "^0.6.7" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/test_login/test_login.js: -------------------------------------------------------------------------------- 1 | var steem = require('steem'); 2 | steem.api.setOptions({url: 'https://api.steemit.com'}); 3 | 4 | /** 5 | * Tests if an username/password pair is correct 6 | * @param {String} username - username of the account 7 | * @param {String} password - password of the account 8 | * @return {boolean} valid - True if the password is correct, false if not (or if the account doesn't exists) 9 | */ 10 | function login_using_password(username, password) { 11 | // Get the private posting key 12 | var wif = steem.auth.toWif(username, password, 'posting'); 13 | 14 | steem.api.getAccounts([username], function (err, result) { 15 | // check if the account exists 16 | if (result.length !== 0) { 17 | // get the public posting key 18 | var pubWif = result[0].posting.key_auths[0][0]; 19 | var valid = false; 20 | try { 21 | // Check if the private key matches the public one. 22 | valid = steem.auth.wifIsValid(wif, pubWif) 23 | } catch (e) { 24 | } 25 | return valid; 26 | } 27 | return false; 28 | }); 29 | } 30 | 31 | /** 32 | * Tests if an username/private key pair is correct 33 | * @param {String} username - username of the account 34 | * @param {String} wif - Private key used for login 35 | * @param {String} type - Type of the private key, can be "posting", "active" or "owner" 36 | * @return {boolean} valid - True if the password is correct, false if not (or if the account doesn't exists) 37 | */ 38 | function login_using_wif(username, wif, type) { 39 | // Get the private posting key 40 | 41 | steem.api.getAccounts([username], function (err, result) { 42 | // check if the account exists 43 | if (result.length !== 0) { 44 | // get the public posting key 45 | if (type === "posting") 46 | var pubWif = result[0].posting.key_auths[0][0]; 47 | else if (type === "active") 48 | var pubWif = result[0].active.key_auths[0][0]; 49 | else if (type === "owner") 50 | var pubWif = result[0].owner.key_auths[0][0]; 51 | 52 | var valid = false; 53 | try { 54 | // Check if the private key matches the public one. 55 | valid = steem.auth.wifIsValid(wif, pubWif) 56 | } catch (e) { 57 | } 58 | return valid; 59 | } 60 | return false; 61 | }); 62 | } -------------------------------------------------------------------------------- /steemjs/transfer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "transfer", 3 | "version": "1.0.0", 4 | "description": "Transfers sp or sbd to another user", 5 | "main": "transfer.js", 6 | "dependencies": { 7 | "steem": "^0.6.7" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/transfer/transfer.js: -------------------------------------------------------------------------------- 1 | var steem = require('steem'); 2 | steem.api.setOptions({url: 'https://api.steemit.com'}); 3 | /** 4 | * Transfers sp or sbd to another account 5 | * @param {String} wif - active key of the account we want to transfer from 6 | * @param {String} from - account who will send the tokens 7 | * @param {String} to - account who will recieve the tokens 8 | * @param {String} amount - Amount of tokens that you want to send, note that it must be written like this : x.xxx unit eg : '1.265 STEEM' or '44.000 SBD' 9 | * @param {String} memo - text you want to add to your transfer 10 | */ 11 | function transfer(wif, from, to, amount, memo) 12 | { 13 | steem.broadcast.transfer(wif, from, to, amount, memo, function(err, result) { 14 | console.log(err, result); 15 | }); 16 | } 17 | // example (note, you can send transfers to yourself) 18 | transfer("wif", "howo", "howo", "0.001 SBD", "You are awesome ! take some tokens") -------------------------------------------------------------------------------- /steemjs/use_testnet/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "use_testnet", 3 | "version": "1.0.0", 4 | "description": "How to use the testnet", 5 | "main": "use_testnet.js", 6 | "dependencies": { 7 | "steem": "^0.6.7" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/use_testnet/use_testnet.js: -------------------------------------------------------------------------------- 1 | var steem = require('steem'); 2 | 3 | var testnet = false; // set to true if you want to use the testnet 4 | 5 | if (testnet) 6 | { 7 | steem.api.setOptions({ url: 'wss://testnet.steem.vc',address_prefix:'STX',chain_id: '79276aea5d4877d9a25892eaa01b0adf019d3e5cb12a97478df3298ccdd01673' }); 8 | steem.config.set('websocket','wss://testnet.steem.vc') 9 | steem.config.set('address_prefix', 'STX') 10 | steem.config.set('chain_id', '79276aea5d4877d9a25892eaa01b0adf019d3e5cb12a97478df3298ccdd01673') 11 | } else 12 | { 13 | steem.api.setOptions({url: 'https://api.steemit.com'}); 14 | } 15 | 16 | 17 | steem.api.getAccounts(['foo'], function(err, response){ 18 | console.log(response[0].balance); // Should be 0.000 STEEM for the mainnet and 1M+ for the testnet 19 | }); 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /steemjs/vote/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vote", 3 | "version": "1.0.0", 4 | "description": "How to cast a vote", 5 | "main": "vote.js", 6 | "dependencies": { 7 | "steem": "^0.6.7" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/vote/vote.js: -------------------------------------------------------------------------------- 1 | var steem = require('steem'); 2 | steem.api.setOptions({url: 'https://api.steemit.com'}); 3 | /** 4 | * Casts a vote. 5 | * @param {String} username - username of the voter account 6 | * @param {String} postingkey - posting key of the voter account 7 | * @param {String} author - Author of the post 8 | * @param {String} permlink - permanent link of the post to comment to. eg : https://steemit.com/programming/@howo/introducting-steemsnippets the permlink is "introducting-steemsnippets" 9 | * @param {int} weight - Power of the vote, can range from -10000 to 10000, 10000 equals a 100% upvote. -10000 equals a 100% flag. 10 | */ 11 | function vote(username, postingkey, author, permlink, weight) 12 | { 13 | steem.broadcast.vote(postingkey, username, author, permlink, weight, function(err, result) { 14 | console.log(err, result); 15 | }); 16 | } 17 | 18 | // example : give a 100% upvote to the post https://steemit.com/programming/@howo/introducting-steemsnippets 19 | vote("username", "postingkey", "howo", "introducting-steemsnippets", 10000); -------------------------------------------------------------------------------- /steemjs/voting_power/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "voting_power", 3 | "version": "1.0.0", 4 | "description": "Gets the voting power of an user", 5 | "main": "voting_power.js", 6 | "dependencies": { 7 | "steem": "^0.6.7" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "Martin Lees", 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /steemjs/voting_power/voting_power.js: -------------------------------------------------------------------------------- 1 | var steem = require('steem'); 2 | steem.api.setOptions({url: 'https://api.steemit.com'}); 3 | /** 4 | * Gets the voting power of an account. code mostly by @asgarth 5 | * @param {String} account - account of whom we want to check the steem power 6 | * @param {String} callback - callback which will have the voting power as parameter 7 | */ 8 | function getvotingpower(account_name, callback) { 9 | return new Promise(resolve => { 10 | steem.api.getAccounts([account_name], function (err, account) { 11 | 12 | account = account[0]; 13 | 14 | const totalShares = parseFloat(account.vesting_shares) + parseFloat(account.received_vesting_shares) - parseFloat(account.delegated_vesting_shares) - parseFloat(account.vesting_withdraw_rate); 15 | 16 | const elapsed = Math.floor(Date.now() / 1000) - account.voting_manabar.last_update_time; 17 | const maxMana = totalShares * 1000000; 18 | // 432000 sec = 5 days 19 | let currentMana = parseFloat(account.voting_manabar.current_mana) + elapsed * maxMana / 432000; 20 | 21 | if (currentMana > maxMana) { 22 | currentMana = maxMana; 23 | } 24 | 25 | const currentManaPerc = currentMana * 100 / maxMana; 26 | 27 | return resolve(currentManaPerc); 28 | }); 29 | }); 30 | } 31 | 32 | 33 | async function example() 34 | { 35 | const vp = await getvotingpower("howo"); 36 | console.log(vp); 37 | } 38 | 39 | example(); --------------------------------------------------------------------------------