├── .eslintrc
├── .gitignore
├── .prettierrc
├── LICENSE
├── README.md
├── package.json
└── tutorials
├── 00_getting_started
└── README.md
├── 01_blog_feed
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── app.scss
│ └── index.html
└── webpack.config.js
├── 02_steemconnect
├── README.md
├── images
│ ├── steemconnect_account_create.png
│ ├── steemconnect_dashboard.png
│ ├── steemconnect_login.png
│ ├── steemconnect_myapps.png
│ ├── steemconnect_new_app.png
│ └── steemconnect_signin.png
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── index.html
│ └── style.css
└── webpack.config.js
├── 03_client_signing
├── README.md
├── images
│ └── overview.png
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 04_get_posts
├── README.md
├── images
│ └── Step-01-UI.png
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 05_get_post_details
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── index.css
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 06_get_voters_list_on_post
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── index.css
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 07_get_post_comments
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── index.css
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 08_get_account_replies
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── index.css
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 09_get_account_comments
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── index.css
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 10_submit_post
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 11_submit_comment_reply
├── README.md
├── images
│ ├── comment_reply_successful_console_output.png
│ └── comment_reply_user_input.png
├── index.js
├── package.json
├── public
│ ├── app.js
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 12_edit_content_patching
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 13_stream_blockchain_transactions
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 14_reblogging_post
├── README.md
├── index.js
├── package.json
├── public
│ ├── app.js
│ ├── index.css
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 15_search_accounts
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── index.css
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 16_search_tags
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── index.css
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 17_vote_on_content
├── README.md
├── index.js
├── package.json
├── public
│ ├── app.js
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 18_follow_a_user
├── README.md
├── index.js
├── package.json
├── public
│ ├── app.js
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 19_get_follower_and_following_list
├── README.md
├── index.js
├── package.json
├── public
│ ├── app.js
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 20_account_reputation
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── index.css
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 21_transfer_steem_and_sbd
├── README.md
├── index.js
├── package.json
├── public
│ ├── app.js
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 22_witness_listing_and_voting
├── README.md
├── index.js
├── package.json
├── public
│ ├── app.js
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 23_claim_rewards
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── index.css
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 24_power_up_steem
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── index.css
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 25_power_down
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── index.css
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 26_create_account
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── index.css
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 27_delegate_power
├── README.md
├── index.js
├── package.json
├── public
│ ├── app.js
│ ├── index.css
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 28_set_withdraw_route
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── public
│ ├── app.js
│ ├── index.css
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 29_get_delegations_by_user
├── README.md
├── index.js
├── package.json
├── public
│ ├── app.js
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 30_grant_posting_permission
├── README.md
├── index.js
├── package.json
├── public
│ ├── app.js
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 31_grant_active_permission
├── README.md
├── index.js
├── package.json
├── public
│ ├── app.js
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 32_convert_sbd_to_steem
├── README.md
├── index.js
├── package.json
├── public
│ ├── app.js
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── 34_get_state_replacement_api
├── README.md
├── index.js
├── package.json
├── public
│ ├── app.js
│ ├── index.css
│ ├── index.html
│ └── style.scss
└── webpack.config.js
├── README.md
├── configuration.js
└── tutorial_structure.md
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "parser": "babel-eslint",
3 | "extends": ["eslint:recommended"],
4 | "env": {
5 | "browser": true,
6 | "es6": true,
7 | "node": true
8 | },
9 | "rules": {
10 | "no-unused-vars": 1,
11 | "no-redeclare": 1,
12 | "no-console": 0
13 | }
14 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (https://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | jspm_packages/
38 |
39 | # Typescript v1 declaration files
40 | typings/
41 |
42 | # Optional npm cache directory
43 | .npm
44 |
45 | # Optional eslint cache
46 | .eslintcache
47 |
48 | # Optional REPL history
49 | .node_repl_history
50 |
51 | # Output of 'npm pack'
52 | *.tgz
53 |
54 | # Yarn Integrity file
55 | .yarn-integrity
56 |
57 | # dotenv environment variables file
58 | .env
59 |
60 | # next.js build output
61 | .next
62 |
63 | # webpack bundles
64 | bundle.js
65 | bundle.js.map
66 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "tabWidth": 4,
3 | "singleQuote": true,
4 | "trailingComma": "es5"
5 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018
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 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "scripts": {
3 | "lint":
4 | "eslint -c .eslintrc —ext .js --ignore-path .gitignore --fix ./tutorials/",
5 | "fmt": "prettier --write ./tutorials/*/*",
6 | "precommit": "lint-staged"
7 | },
8 | "lint-staged": {
9 | "*.{png,jpeg,jpg,gif,svg}": ["imagemin-lint-staged", "git add"],
10 | "*.{js,json,css,md,lock}": ["prettier --write", "git add"]
11 | },
12 | "devDependencies": {
13 | "babel-eslint": "^8.0.3",
14 | "babel-jest": "^21.2.0",
15 | "babel-preset-react-native": "^4.0.0",
16 | "eslint": "^4.12.1",
17 | "eslint-config-airbnb-base": "^12.1.0",
18 | "eslint-plugin-babel": "^4.1.2",
19 | "eslint-plugin-import": "^2.10.0",
20 | "husky": "^0.14.3",
21 | "imagemin-lint-staged": "^0.3.0",
22 | "lint-staged": "^7.1.0",
23 | "prettier": "1.11.1"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/tutorials/00_getting_started/README.md:
--------------------------------------------------------------------------------
1 | # Getting Started
2 |
3 | Prepare your development environment to use Javascript with the Steem blockchain.
4 |
5 | For Javascript tutorials, we will use the opensource library [dsteem](https://github.com/steemit/dsteem).
6 |
7 | ### Node.js
8 |
9 | To get the most out of these tutorials, you should be familiar with [Node.js](https://nodejs.org/en/), [ES6](https://babeljs.io/learn-es2015/) aka [es2015](http://www.ecma-international.org/ecma-262/6.0/), the DOM, and modern Javascript programming practices.
10 | You can still learn a lot of these if they aren't in your base skill-set; it'll be much easier if they are.
11 |
12 | ### Your Dev Environment
13 |
14 | These tutorials require [Node.js 8.7+](https://nodejs.org/en/download/). [Yarn](https://yarnpkg.com/en/) is nice, but not required. Runnable versions of the tutorials are located [in this github repo](https://github.com/steemit/devportal-tutorials-js).
15 | If you haven't chosen an editor, you can use [Atom](https://atom.io/), [Sublime](https://www.sublimetext.com/), [Intellij](https://www.jetbrains.com/idea/), [Vi](https://en.wikipedia.org/wiki/Vi), etc.
16 |
17 | If you want to keep multiple versions of Node on your system try [Node Version Manager](https://github.com/creationix/nvm).
18 |
19 | ### Running a typical Tutorial
20 |
21 | Let's say you wanted to run the very [first tutorial](../01_blog_feed), `01_blog_feed`. Here's how you'd do it:
22 |
23 | 1. From Bash:
24 |
25 | ```bash
26 | git clone https://github.com/steemit/devportal-tutorials-js.git
27 |
28 | cd devportal-tutorials-js/tutorials/01_blog_feed
29 | npm i
30 | npm run dev-server
31 | ```
32 |
33 | 1. open http://localhost:3000/ in your web browser
34 |
35 | ```
36 | ### Github
37 |
38 | If you'd rather clone projects in a windowed environment rather than the terminal, consider [Github Desktop](https://desktop.github.com/).
39 | ```
40 |
--------------------------------------------------------------------------------
/tutorials/01_blog_feed/index.js:
--------------------------------------------------------------------------------
1 | const Koa = require('koa');
2 | const app = new Koa();
3 | const serve = require('koa-static');
4 | app.use(serve('./public'));
5 |
6 | app.listen(3000);
7 |
8 | console.log('listening on port 3000');
9 |
--------------------------------------------------------------------------------
/tutorials/01_blog_feed/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "01_blog_feed",
3 | "version": "0.0.1",
4 | "description": "Pull the list of a user's posts from steem",
5 | "main": "server.js",
6 | "scripts": {
7 | "start": "webpack && node ./index.js",
8 | "test": "echo \"Error: no test specified\" && exit 1",
9 | "dev-server":
10 | "./node_modules/.bin/webpack-dev-server --mode development --content-base ./public --port 3000"
11 | },
12 | "author": "",
13 | "license": "ISC",
14 | "dependencies": {
15 | "bootstrap": "^4.1.3",
16 | "dsteem": "^0.10.1",
17 | "koa": "^2.5.3",
18 | "koa-static": "^5.0.0",
19 | "webpack-serve": "^2.0.2"
20 | },
21 | "devDependencies": {
22 | "css-loader": "^1.0.0",
23 | "extract-text-webpack-plugin": "^3.0.2",
24 | "node-sass": "^4.9.3",
25 | "sass-loader": "^7.1.0",
26 | "style-loader": "^0.23.1",
27 | "webpack": "^4.20.2",
28 | "webpack-cli": "^3.1.2",
29 | "webpack-dev-server": "^3.1.9"
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tutorials/01_blog_feed/public/app.js:
--------------------------------------------------------------------------------
1 | import { Client } from 'dsteem';
2 |
3 | const client = new Client('https://api.steemit.com');
4 |
5 | function fetchBlog() {
6 | const query = {
7 | tag: 'steemitblog',
8 | limit: 5,
9 | };
10 | client.database
11 | .getDiscussions('blog', query)
12 | .then(result => {
13 | var posts = [];
14 | result.forEach(post => {
15 | const json = JSON.parse(post.json_metadata);
16 | const image = json.image ? json.image[0] : '';
17 | const title = post.title;
18 | const author = post.author;
19 | const created = new Date(post.created).toDateString();
20 | posts.push(
21 | `
7 |
Welcome to my blog!
8 |
9 |
10 |
--------------------------------------------------------------------------------
/tutorials/01_blog_feed/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | module.exports = {
3 | entry: ['./public/app.js', './public/app.scss'],
4 | output: {
5 | path: path.resolve(__dirname, 'public'),
6 | filename: 'bundle.js',
7 | },
8 | devtool: 'source-map',
9 | module: {
10 | rules: [
11 | {
12 | test: /\.scss$/,
13 | use: [
14 | {
15 | loader: 'style-loader', // creates style nodes from JS strings
16 | },
17 | {
18 | loader: 'css-loader', // translates CSS into CommonJS
19 | },
20 | {
21 | loader: 'sass-loader', // compiles Sass to CSS
22 | },
23 | ],
24 | },
25 | ],
26 | },
27 | };
28 |
--------------------------------------------------------------------------------
/tutorials/02_steemconnect/images/steemconnect_account_create.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/steemit/devportal-tutorials-js/f20dcc475775def4488daf5b66b5f1bd35bdb8c5/tutorials/02_steemconnect/images/steemconnect_account_create.png
--------------------------------------------------------------------------------
/tutorials/02_steemconnect/images/steemconnect_dashboard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/steemit/devportal-tutorials-js/f20dcc475775def4488daf5b66b5f1bd35bdb8c5/tutorials/02_steemconnect/images/steemconnect_dashboard.png
--------------------------------------------------------------------------------
/tutorials/02_steemconnect/images/steemconnect_login.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/steemit/devportal-tutorials-js/f20dcc475775def4488daf5b66b5f1bd35bdb8c5/tutorials/02_steemconnect/images/steemconnect_login.png
--------------------------------------------------------------------------------
/tutorials/02_steemconnect/images/steemconnect_myapps.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/steemit/devportal-tutorials-js/f20dcc475775def4488daf5b66b5f1bd35bdb8c5/tutorials/02_steemconnect/images/steemconnect_myapps.png
--------------------------------------------------------------------------------
/tutorials/02_steemconnect/images/steemconnect_new_app.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/steemit/devportal-tutorials-js/f20dcc475775def4488daf5b66b5f1bd35bdb8c5/tutorials/02_steemconnect/images/steemconnect_new_app.png
--------------------------------------------------------------------------------
/tutorials/02_steemconnect/images/steemconnect_signin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/steemit/devportal-tutorials-js/f20dcc475775def4488daf5b66b5f1bd35bdb8c5/tutorials/02_steemconnect/images/steemconnect_signin.png
--------------------------------------------------------------------------------
/tutorials/02_steemconnect/index.js:
--------------------------------------------------------------------------------
1 | const Koa = require('koa');
2 | const app = new Koa();
3 | const serve = require('koa-static');
4 | app.use(serve('./public'));
5 |
6 | app.listen(3000);
7 |
8 | console.log('listening on port 3000');
9 |
--------------------------------------------------------------------------------
/tutorials/02_steemconnect/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "02_steemconnect",
3 | "version": "1.0.0",
4 | "description": "Getting started with Steemconnect",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "webpack && node ./index.js",
8 | "test": "echo \"Error: no test specified\" && exit 1",
9 | "dev-server":
10 | "./node_modules/.bin/webpack-dev-server --mode development --content-base ./public --port 3000"
11 | },
12 | "author": "",
13 | "license": "ISC",
14 | "dependencies": {
15 | "koa": "^2.5.3",
16 | "koa-static": "^5.0.0",
17 | "sc2-sdk": "^2.0.1"
18 | },
19 | "devDependencies": {
20 | "webpack": "^4.20.2",
21 | "webpack-cli": "^3.1.2",
22 | "webpack-dev-server": "^3.1.9"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tutorials/02_steemconnect/public/app.js:
--------------------------------------------------------------------------------
1 | const sc2 = require('sc2-sdk');
2 |
3 | // init steemconnect
4 | let api = sc2.Initialize({
5 | app: 'demo-app',
6 | callbackURL: 'http://localhost:3000',
7 | accessToken: 'access_token',
8 | scope: ['vote', 'comment'],
9 | });
10 | // get login URL
11 | let link = api.getLoginURL();
12 |
13 | // acquire access_token and username after authorization
14 | let access_token = new URLSearchParams(document.location.search).get(
15 | 'access_token'
16 | );
17 | let username = new URLSearchParams(document.location.search).get('username');
18 |
19 | let lt = '',
20 | ut = '',
21 | lo = '',
22 | jt = '',
23 | t = '';
24 | if (access_token) {
25 | // set access token after login
26 | api.setAccessToken(access_token);
27 |
28 | // Logout button
29 | lt = `
Log Out `;
30 | // User name after successfull login
31 | ut = `
User: ${username}
`;
32 | // Get user details button
33 | lo = `
Get User details `;
34 | // User details JSON output
35 | jt = `
`;
36 |
37 | t = lt + ut + lo + jt;
38 | } else {
39 | // Login button
40 | t = `
Log In `;
41 | }
42 |
43 | // set template
44 | document.getElementById('content').innerHTML = t;
45 |
46 | // Logout function, revoke access token
47 | window.logOut = () => {
48 | api.revokeToken(function(err, res) {
49 | if (res && res.success) {
50 | access_token = null;
51 | document.location.href = '/';
52 | }
53 | });
54 | return false;
55 | };
56 |
57 | // Get User details function, returns user data via Steemconnect API
58 | window.getUserDetails = () => {
59 | api.me(function(err, res) {
60 | if (res) {
61 | const user = JSON.stringify(res, undefined, 2);
62 | document.getElementById('userDetailsJSON').innerHTML = user;
63 | }
64 | });
65 | };
66 |
--------------------------------------------------------------------------------
/tutorials/02_steemconnect/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Getting started with Steemconnect
4 |
5 |
6 |
Steemconnect
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/tutorials/02_steemconnect/public/style.css:
--------------------------------------------------------------------------------
1 | a:link, a:visited {
2 | background-color: gray;
3 | color: white;
4 | padding: 7px 12px;
5 | text-align: center;
6 | text-decoration: none;
7 | display: inline-block;
8 | }
9 | a:hover, a:active {
10 | background-color: blue;
11 | }
--------------------------------------------------------------------------------
/tutorials/02_steemconnect/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | module.exports = {
3 | entry: './public/app.js',
4 | output: {
5 | path: path.resolve(__dirname, 'public'),
6 | filename: 'bundle.js',
7 | },
8 | };
9 |
--------------------------------------------------------------------------------
/tutorials/03_client_signing/images/overview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/steemit/devportal-tutorials-js/f20dcc475775def4488daf5b66b5f1bd35bdb8c5/tutorials/03_client_signing/images/overview.png
--------------------------------------------------------------------------------
/tutorials/03_client_signing/index.js:
--------------------------------------------------------------------------------
1 | const Koa = require('koa');
2 | const app = new Koa();
3 | const serve = require('koa-static');
4 | app.use(serve('./public'));
5 |
6 | app.listen(3000);
7 |
8 | console.log('listening on port 3000');
9 |
--------------------------------------------------------------------------------
/tutorials/03_client_signing/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "03_client_signing",
3 | "version": "1.0.0",
4 | "description": "Client signing on Steem",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "webpack && node ./index.js",
8 | "test": "echo \"Error: no test specified\" && exit 1",
9 | "dev-server":
10 | "./node_modules/.bin/webpack-dev-server --mode development --content-base ./public --port 3000"
11 | },
12 | "author": "",
13 | "license": "ISC",
14 | "dependencies": {
15 | "bootstrap": "^4.1.3",
16 | "dsteem": "^0.10.1",
17 | "koa": "^2.5.3",
18 | "koa-static": "^5.0.0"
19 | },
20 | "devDependencies": {
21 | "css-loader": "^1.0.0",
22 | "node-sass": "^4.9.3",
23 | "postcss-loader": "^3.0.0",
24 | "precss": "^3.1.2",
25 | "sass-loader": "^7.1.0",
26 | "style-loader": "^0.23.1",
27 | "webpack": "^4.20.2",
28 | "webpack-cli": "^3.1.2",
29 | "webpack-dev-server": "^3.1.9"
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tutorials/03_client_signing/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Client-side transaction signing
4 |
5 |
6 |
7 |
8 |
12 |
13 |
14 |
15 |
16 | Select account to operate with
17 |
18 |
19 |
20 |
21 |
22 | Select operation type
23 | Vote
24 | Follow
25 | Reblog
26 |
27 |
28 |
33 |
34 |
40 |
41 |
47 |
48 | Generate Transaction
49 | Sign Transaction
50 | Verify Signature
51 | Broadcast Transaction
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/tutorials/03_client_signing/public/style.scss:
--------------------------------------------------------------------------------
1 | import 'bootstrap/dist/css/bootstrap.min.css'
--------------------------------------------------------------------------------
/tutorials/03_client_signing/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | module.exports = {
3 | entry: ['./public/app.js', './public/style.scss'],
4 | output: {
5 | path: path.resolve(__dirname, 'public'),
6 | filename: 'bundle.js',
7 | },
8 | devtool: 'source-map',
9 | module: {
10 | rules: [
11 | {
12 | test: /\.css$/,
13 | use: ['style-loader', 'css-loader'],
14 | },
15 | ],
16 | },
17 | performance: {
18 | hints: process.env.NODE_ENV === 'production' ? 'warning' : false,
19 | },
20 | };
21 |
--------------------------------------------------------------------------------
/tutorials/04_get_posts/images/Step-01-UI.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/steemit/devportal-tutorials-js/f20dcc475775def4488daf5b66b5f1bd35bdb8c5/tutorials/04_get_posts/images/Step-01-UI.png
--------------------------------------------------------------------------------
/tutorials/04_get_posts/index.js:
--------------------------------------------------------------------------------
1 | const Koa = require('koa');
2 | const app = new Koa();
3 | const serve = require('koa-static');
4 | app.use(serve('./public'));
5 |
6 | app.listen(3000);
7 |
8 | console.log('listening on port 3000');
9 |
--------------------------------------------------------------------------------
/tutorials/04_get_posts/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "04_get_posts",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "webpack --config webpack.config.js && node ./index.js",
8 | "test": "echo \"Error: no test specified\" && exit 1",
9 | "dev-server":
10 | "./node_modules/.bin/webpack-dev-server --mode development --content-base ./public --port 3000"
11 | },
12 | "author": "",
13 | "license": "ISC",
14 | "dependencies": {
15 | "bootstrap": "^4.1.3",
16 | "dsteem": "^0.10.1",
17 | "koa": "^2.5.3",
18 | "koa-static": "^5.0.0"
19 | },
20 | "devDependencies": {
21 | "css-loader": "^1.0.0",
22 | "style-loader": "^0.23.1",
23 | "webpack": "^4.20.2",
24 | "webpack-cli": "^3.1.2",
25 | "webpack-dev-server": "^3.1.9"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tutorials/04_get_posts/public/app.js:
--------------------------------------------------------------------------------
1 | const dsteem = require('dsteem');
2 |
3 | let opts = {};
4 |
5 | //connect to production server
6 | opts.addressPrefix = 'STM';
7 | opts.chainId =
8 | '0000000000000000000000000000000000000000000000000000000000000000';
9 |
10 | //connect to server which is connected to the network/production
11 | const client = new dsteem.Client('https://api.steemit.com');
12 |
13 | //filter change selection function
14 | window.getPosts = async () => {
15 | const filter = document.getElementById('filters').value;
16 | const query = {
17 | tag: document.getElementById('tag').value,
18 | limit: 5,
19 | };
20 |
21 | console.log('Post assembled.\nFilter:', filter, '\nQuery:', query);
22 |
23 | client.database
24 | .getDiscussions(filter, query)
25 | .then(result => {
26 | console.log('Response received:', result);
27 | if (result) {
28 | var posts = [];
29 | result.forEach(post => {
30 | const json = JSON.parse(post.json_metadata);
31 | const image = json.image ? json.image[0] : '';
32 | const title = post.title;
33 | const author = post.author;
34 | const created = new Date(post.created).toDateString();
35 | posts.push(
36 | `
${title} by ${author}
${created}
`
37 | );
38 | });
39 |
40 | document.getElementById('postList').innerHTML = posts.join('');
41 | } else {
42 | document.getElementById('postList').innerHTML = 'No result.';
43 | }
44 | })
45 | .catch(err => {
46 | console.log(err);
47 | alert(`Error:${err}, try again`);
48 | });
49 | };
50 |
--------------------------------------------------------------------------------
/tutorials/04_get_posts/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Get posts using filters & tags
4 |
5 |
6 |
7 |
8 |
9 |
10 | Filters
11 |
12 |
13 | Select filter
14 | Trending
15 | Hot
16 | New
17 | Promoted
18 |
19 |
20 |
21 |
22 |
23 | Tag
24 |
25 |
26 |
27 |
28 |
29 |
30 | Get Posts
31 |
32 |
33 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/tutorials/04_get_posts/public/style.scss:
--------------------------------------------------------------------------------
1 | import 'bootstrap/dist/css/bootstrap.min.css'
2 |
--------------------------------------------------------------------------------
/tutorials/04_get_posts/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | module.exports = {
3 | entry: ['./public/app.js', './public/style.scss'],
4 | output: {
5 | path: path.resolve(__dirname, 'public'),
6 | filename: 'bundle.js',
7 | },
8 | devtool: 'source-map',
9 | module: {
10 | rules: [
11 | {
12 | test: /\.css$/,
13 | use: ['style-loader', 'css-loader'],
14 | },
15 | ],
16 | },
17 | performance: {
18 | hints: process.env.NODE_ENV === 'production' ? 'warning' : false,
19 | },
20 | };
21 |
--------------------------------------------------------------------------------
/tutorials/05_get_post_details/index.js:
--------------------------------------------------------------------------------
1 | const Koa = require('koa');
2 | const app = new Koa();
3 | const serve = require('koa-static');
4 | app.use(serve('./public'));
5 |
6 | app.listen(3000);
7 |
8 | console.log('listening on port 3000');
9 |
--------------------------------------------------------------------------------
/tutorials/05_get_post_details/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "05_get_post_details",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "webpack && node ./index.js",
8 | "test": "echo \"Error: no test specified\" && exit 1",
9 | "dev-server":
10 | "./node_modules/.bin/webpack-dev-server --mode development --content-base ./public --port 3000"
11 | },
12 | "author": "",
13 | "license": "ISC",
14 | "dependencies": {
15 | "bootstrap": "^4.1.3",
16 | "dsteem": "^0.10.1",
17 | "koa": "^2.5.3",
18 | "koa-static": "^5.0.0",
19 | "remarkable": "^1.7.1"
20 | },
21 | "devDependencies": {
22 | "css-loader": "^1.0.0",
23 | "style-loader": "^0.23.1",
24 | "webpack": "^4.20.2",
25 | "webpack-cli": "^3.1.2",
26 | "webpack-dev-server": "^3.1.9"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/tutorials/05_get_post_details/public/app.js:
--------------------------------------------------------------------------------
1 | const dsteem = require('dsteem');
2 | const Remarkable = require('remarkable');
3 |
4 | let opts = {};
5 |
6 | //connect to production server
7 | opts.addressPrefix = 'STM';
8 | opts.chainId =
9 | '0000000000000000000000000000000000000000000000000000000000000000';
10 | //connect to server which is connected to the network/production
11 | const client = new dsteem.Client('https://api.steemit.com');
12 |
13 | //fetch list of trending posts
14 | async function main() {
15 | const query = {
16 | tag: '',
17 | limit: 5,
18 | truncate_body: 1,
19 | };
20 | client.database
21 | .getDiscussions('trending', query)
22 | .then(result => {
23 | var posts = [];
24 | result.forEach(post => {
25 | console.log(post);
26 | const json = JSON.parse(post.json_metadata);
27 | const image = json.image ? json.image[0] : '';
28 | const title = post.title;
29 | const author = post.author;
30 | const permlink = post.permlink;
31 | const created = new Date(post.created).toDateString();
32 | posts.push(
33 | `
${title} by ${author}
${created}
`
34 | );
35 | });
36 | document.getElementById('postList').style.display = 'block';
37 | document.getElementById('postList').innerHTML = posts.join('');
38 | })
39 | .catch(err => {
40 | console.log(err);
41 | alert('Error occured, please reload the page');
42 | });
43 | }
44 | //catch error messages
45 | main().catch(console.error);
46 |
47 | //get_content of the post
48 | window.openPost = async (author, permlink) => {
49 | client.database.call('get_content', [author, permlink]).then(result => {
50 | const md = new Remarkable({ html: true, linkify: true });
51 | const body = md.render(result.body);
52 | const content = `
Close
${
53 | result.title
54 | } ${body}
`;
55 |
56 | document.getElementById('postList').style.display = 'none';
57 | document.getElementById('postBody').style.display = 'block';
58 | document.getElementById('postBody').innerHTML = content;
59 | });
60 | };
61 | //go back from post view to list
62 | window.goback = async () => {
63 | document.getElementById('postList').style.display = 'block';
64 | document.getElementById('postBody').style.display = 'none';
65 | };
66 |
--------------------------------------------------------------------------------
/tutorials/05_get_post_details/public/index.css:
--------------------------------------------------------------------------------
1 | #postBody img, #postBody iframe {
2 | max-width: 100%;
3 | }
4 | #postBody .pull-right {
5 | float: right !important;
6 | }
7 |
--------------------------------------------------------------------------------
/tutorials/05_get_post_details/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Get post details
4 |
5 |
6 |
7 |
8 |
To get post details select any post
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/tutorials/05_get_post_details/public/style.scss:
--------------------------------------------------------------------------------
1 | import 'bootstrap/dist/css/bootstrap.min.css'
2 | import './index.css'
--------------------------------------------------------------------------------
/tutorials/05_get_post_details/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | module.exports = {
3 | entry: ['./public/app.js', './public/style.scss'],
4 | output: {
5 | path: path.resolve(__dirname, 'public'),
6 | filename: 'bundle.js',
7 | },
8 | devtool: 'source-map',
9 | module: {
10 | rules: [
11 | {
12 | test: /\.css$/,
13 | use: ['style-loader', 'css-loader'],
14 | },
15 | ],
16 | },
17 | performance: {
18 | hints: process.env.NODE_ENV === 'production' ? 'warning' : false,
19 | },
20 | };
21 |
--------------------------------------------------------------------------------
/tutorials/06_get_voters_list_on_post/index.js:
--------------------------------------------------------------------------------
1 | const Koa = require('koa');
2 | const app = new Koa();
3 | const serve = require('koa-static');
4 | app.use(serve('./public'));
5 |
6 | app.listen(3000);
7 |
8 | console.log('listening on port 3000');
9 |
--------------------------------------------------------------------------------
/tutorials/06_get_voters_list_on_post/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "06_get_post_details",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "webpack && node ./index.js",
8 | "test": "echo \"Error: no test specified\" && exit 1",
9 | "dev-server":
10 | "./node_modules/.bin/webpack-dev-server --mode development --content-base ./public --port 3000"
11 | },
12 | "author": "",
13 | "license": "ISC",
14 | "dependencies": {
15 | "bootstrap": "^4.1.3",
16 | "dsteem": "^0.10.1",
17 | "koa": "^2.5.3",
18 | "koa-static": "^5.0.0",
19 | "remarkable": "^1.7.1"
20 | },
21 | "devDependencies": {
22 | "css-loader": "^1.0.0",
23 | "style-loader": "^0.23.1",
24 | "webpack": "^4.20.2",
25 | "webpack-cli": "^3.1.2",
26 | "webpack-dev-server": "^3.1.9"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/tutorials/06_get_voters_list_on_post/public/app.js:
--------------------------------------------------------------------------------
1 | const dsteem = require('dsteem');
2 |
3 | let opts = {};
4 |
5 | //connect to production server
6 | opts.addressPrefix = 'STM';
7 | opts.chainId =
8 | '0000000000000000000000000000000000000000000000000000000000000000';
9 | //connect to server which is connected to the network/production
10 | const client = new dsteem.Client('https://api.steemit.com');
11 |
12 | //fetch list of trending posts
13 | async function main() {
14 | const query = {
15 | tag: '',
16 | limit: 5,
17 | truncate_body: 1,
18 | };
19 | client.database
20 | .getDiscussions('trending', query)
21 | .then(result => {
22 | var posts = [];
23 | result.forEach(post => {
24 | console.log('post', post);
25 | const json = JSON.parse(post.json_metadata);
26 | const image = json.image ? json.image[0] : '';
27 | const title = post.title;
28 | const author = post.author;
29 | const permlink = post.permlink;
30 | const created = new Date(post.created).toDateString();
31 | posts.push(
32 | `
${title} by ${author}
${created}
`
33 | );
34 | });
35 | document.getElementById('postList').style.display = 'block';
36 | document.getElementById('postList').innerHTML = posts.join('');
37 | })
38 | .catch(err => {
39 | console.log(err);
40 | alert('Error occured, please reload the page');
41 | });
42 | }
43 | //catch error messages
44 | main().catch(console.error);
45 |
46 | //get_content of the post
47 | window.openPost = async (author, permlink) => {
48 | client.database
49 | .call('get_active_votes', [author, permlink])
50 | .then(result => {
51 | console.log('votes', result, JSON.stringify(result));
52 |
53 | var voters = [];
54 | voters.push(
55 | `
Close
`
56 | );
57 | result.forEach(voter => {
58 | const name = voter.voter;
59 | const time = new Date(voter.time).toDateString();
60 | voters.push(`${name} (${time})`);
61 | });
62 |
63 | document.getElementById('postList').style.display = 'none';
64 | document.getElementById('postBody').style.display = 'block';
65 | document.getElementById('postBody').innerHTML = voters.join('
');
66 | });
67 | };
68 | //go back from post view to list
69 | window.goback = async () => {
70 | document.getElementById('postList').style.display = 'block';
71 | document.getElementById('postBody').style.display = 'none';
72 | };
73 |
--------------------------------------------------------------------------------
/tutorials/06_get_voters_list_on_post/public/index.css:
--------------------------------------------------------------------------------
1 | #postBody img, #postBody iframe {
2 | max-width: 100%;
3 | }
4 | #postBody .pull-right {
5 | float: right !important;
6 | }
7 |
--------------------------------------------------------------------------------
/tutorials/06_get_voters_list_on_post/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Get post details
4 |
5 |
6 |
7 |
8 |
To get voters list on post, select any post
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/tutorials/06_get_voters_list_on_post/public/style.scss:
--------------------------------------------------------------------------------
1 | import 'bootstrap/dist/css/bootstrap.min.css'
2 | import './index.css'
--------------------------------------------------------------------------------
/tutorials/06_get_voters_list_on_post/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | module.exports = {
3 | entry: ['./public/app.js', './public/style.scss'],
4 | output: {
5 | path: path.resolve(__dirname, 'public'),
6 | filename: 'bundle.js',
7 | },
8 | devtool: 'source-map',
9 | module: {
10 | rules: [
11 | {
12 | test: /\.css$/,
13 | use: ['style-loader', 'css-loader'],
14 | },
15 | ],
16 | },
17 | performance: {
18 | hints: process.env.NODE_ENV === 'production' ? 'warning' : false,
19 | },
20 | };
21 |
--------------------------------------------------------------------------------
/tutorials/07_get_post_comments/index.js:
--------------------------------------------------------------------------------
1 | const Koa = require('koa');
2 | const app = new Koa();
3 | const serve = require('koa-static');
4 | app.use(serve('./public'));
5 |
6 | app.listen(3000);
7 |
8 | console.log('listening on port 3000');
9 |
--------------------------------------------------------------------------------
/tutorials/07_get_post_comments/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "07_get_post_comments",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "webpack && node ./index.js",
8 | "test": "echo \"Error: no test specified\" && exit 1",
9 | "dev-server":
10 | "./node_modules/.bin/webpack-dev-server --mode development --content-base ./public --port 3000"
11 | },
12 | "author": "",
13 | "license": "ISC",
14 | "dependencies": {
15 | "bootstrap": "^4.1.3",
16 | "dsteem": "^0.10.1",
17 | "koa": "^2.5.3",
18 | "koa-static": "^5.0.0",
19 | "remarkable": "^1.7.1"
20 | },
21 | "devDependencies": {
22 | "css-loader": "^1.0.0",
23 | "style-loader": "^0.23.1",
24 | "webpack": "^4.20.2",
25 | "webpack-cli": "^3.1.2",
26 | "webpack-dev-server": "^3.1.9"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/tutorials/07_get_post_comments/public/app.js:
--------------------------------------------------------------------------------
1 | const dsteem = require('dsteem');
2 | const Remarkable = require('remarkable');
3 |
4 | let opts = {};
5 |
6 | //connect to production server
7 | opts.addressPrefix = 'STM';
8 | opts.chainId =
9 | '0000000000000000000000000000000000000000000000000000000000000000';
10 | //connect to server which is connected to the network/production
11 | const client = new dsteem.Client('https://api.steemit.com');
12 |
13 | //fetch list of trending posts
14 | async function main() {
15 | const query = {
16 | tag: '',
17 | limit: 5,
18 | truncate_body: 1,
19 | };
20 | client.database
21 | .getDiscussions('trending', query)
22 | .then(result => {
23 | var posts = [];
24 | result.forEach(post => {
25 | const json = JSON.parse(post.json_metadata);
26 | const image = json.image ? json.image[0] : '';
27 | const title = post.title;
28 | const author = post.author;
29 | const permlink = post.permlink;
30 | const created = new Date(post.created).toDateString();
31 | posts.push(
32 | `${title} by ${author}
${created}
`
33 | );
34 | });
35 | document.getElementById('postList').style.display = 'block';
36 | document.getElementById('postList').innerHTML = posts.join('');
37 | })
38 | .catch(err => {
39 | console.log(err);
40 | alert('Error occured, please reload the page');
41 | });
42 | }
43 | //catch error messages
44 | main().catch(console.error);
45 |
46 | //get_content of the post and get_content_replies
47 | window.openPost = async (author, permlink) => {
48 | client.database.call('get_content', [author, permlink]).then(result => {
49 | const md = new Remarkable({ html: true, linkify: true });
50 | const body = md.render(result.body);
51 | const content = `Close
${
52 | result.title
53 | } ${body} `;
54 |
55 | document.getElementById('postList').style.display = 'none';
56 | document.getElementById('postBody').style.display = 'block';
57 | document.getElementById('postBody').innerHTML = content;
58 |
59 | //get_content_replies of the selected post
60 | client.database
61 | .call('get_content_replies', [author, permlink])
62 | .then(result => {
63 | const comments = [];
64 | for (var i = 0; i < result.length; i++) {
65 | comments.push(
66 | `\
67 |
\
68 |
@${result[i].author} \
69 | ${new Date(
70 | result[i].created
71 | ).toString()} \
72 | \
73 |
${md.render(result[i].body)}
\
74 |
▲ ${
75 | result[i].net_votes
76 | } \
77 |
`
78 | );
79 | }
80 | document.getElementById('postComments').style.display = 'block';
81 | document.getElementById(
82 | 'postComments'
83 | ).innerHTML = comments.join('');
84 | });
85 | });
86 | };
87 | //go back from post view to list
88 | window.goback = async () => {
89 | document.getElementById('postList').style.display = 'block';
90 | document.getElementById('postBody').style.display = 'none';
91 | document.getElementById('postComments').style.display = 'none';
92 | };
93 |
--------------------------------------------------------------------------------
/tutorials/07_get_post_comments/public/index.css:
--------------------------------------------------------------------------------
1 | #postBody img,
2 | #postBody iframe {
3 | max-width: 100%;
4 | }
5 | #postBody .pull-right {
6 | float: right !important;
7 | }
8 |
9 | .list-group-item-heading {
10 | cursor:pointer;
11 | }
--------------------------------------------------------------------------------
/tutorials/07_get_post_comments/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Get post comments
4 |
5 |
6 |
7 |
8 |
To get post comments select any post
9 |
10 |
11 |
12 |
13 |
14 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/tutorials/07_get_post_comments/public/style.scss:
--------------------------------------------------------------------------------
1 | import 'bootstrap/dist/css/bootstrap.min.css'
2 | import './index.css'
--------------------------------------------------------------------------------
/tutorials/07_get_post_comments/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | module.exports = {
3 | entry: ['./public/app.js', './public/style.scss'],
4 | output: {
5 | path: path.resolve(__dirname, 'public'),
6 | filename: 'bundle.js',
7 | },
8 | devtool: 'source-map',
9 | module: {
10 | rules: [
11 | {
12 | test: /\.css$/,
13 | use: ['style-loader', 'css-loader'],
14 | },
15 | ],
16 | },
17 | performance: {
18 | hints: process.env.NODE_ENV === 'production' ? 'warning' : false,
19 | },
20 | };
21 |
--------------------------------------------------------------------------------
/tutorials/08_get_account_replies/index.js:
--------------------------------------------------------------------------------
1 | const Koa = require('koa');
2 | const app = new Koa();
3 | const serve = require('koa-static');
4 | app.use(serve('./public'));
5 |
6 | app.listen(3000);
7 |
8 | console.log('listening on port 3000');
9 |
--------------------------------------------------------------------------------
/tutorials/08_get_account_replies/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "08_get_account_replies",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "webpack && node ./index.js",
8 | "test": "echo \"Error: no test specified\" && exit 1",
9 | "dev-server":
10 | "./node_modules/.bin/webpack-dev-server --mode development --content-base ./public --port 3000"
11 | },
12 | "author": "",
13 | "license": "ISC",
14 | "dependencies": {
15 | "bootstrap": "^4.1.3",
16 | "dsteem": "^0.10.1",
17 | "koa": "^2.5.3",
18 | "koa-static": "^5.0.0",
19 | "remarkable": "^1.7.1"
20 | },
21 | "devDependencies": {
22 | "css-loader": "^1.0.0",
23 | "style-loader": "^0.23.1",
24 | "webpack": "^4.20.2",
25 | "webpack-cli": "^3.1.2",
26 | "webpack-dev-server": "^3.1.9"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/tutorials/08_get_account_replies/public/app.js:
--------------------------------------------------------------------------------
1 | const dsteem = require('dsteem');
2 | let opts = {};
3 | //connect to production server
4 | opts.addressPrefix = 'STM';
5 | opts.chainId =
6 | '0000000000000000000000000000000000000000000000000000000000000000';
7 | //connect to server which is connected to the network/production
8 | const client = new dsteem.Client('https://api.steemit.com');
9 |
10 | const Remarkable = require('remarkable');
11 | const md = new Remarkable({html: true, linkify: true});
12 |
13 |
14 | //fetch list of replies for certain account
15 | async function main() {
16 | const query = '/@steemitblog/recent-replies';
17 | client.database
18 | .call('get_state', [query])
19 | .then(result => {
20 | if (!(Object.keys(result.content).length === 0 && result.content.constructor === Object)) {
21 | var replies = [];
22 | Object.keys(result.content).forEach(key => {
23 | const reply = result.content[key];
24 | const author = reply.author;
25 | const created = new Date(reply.created).toDateString();
26 | const body = md.render(reply.body);
27 | const netvotes = reply.net_votes;
28 | replies.push(
29 | `\
30 |
\
31 |
@${author} \
32 | ${created} \
33 | \
34 |
${body}
\
35 |
▲ ${netvotes} \
36 |
`
37 | );
38 | });
39 | document.getElementById('replies').style.display = 'block';
40 | document.getElementById('replies').innerHTML = replies.join('');
41 | }
42 | })
43 | .catch(err => {
44 | console.log(err);
45 | alert('Error occured, please reload the page');
46 | });
47 | }
48 | //catch error messages
49 | main().catch(console.error);
50 |
--------------------------------------------------------------------------------
/tutorials/08_get_account_replies/public/index.css:
--------------------------------------------------------------------------------
1 | #replies img,
2 | #replies iframe {
3 | max-width: 100%;
4 | }
5 |
--------------------------------------------------------------------------------
/tutorials/08_get_account_replies/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Get account replies
4 |
5 |
6 |
7 |
8 |
Recent replies on @steemitblog's content
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/tutorials/08_get_account_replies/public/style.scss:
--------------------------------------------------------------------------------
1 | import 'bootstrap/dist/css/bootstrap.min.css'
2 | import './index.css'
--------------------------------------------------------------------------------
/tutorials/08_get_account_replies/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | module.exports = {
3 | entry: ['./public/app.js', './public/style.scss'],
4 | output: {
5 | path: path.resolve(__dirname, 'public'),
6 | filename: 'bundle.js',
7 | },
8 | devtool: 'source-map',
9 | module: {
10 | rules: [
11 | {
12 | test: /\.css$/,
13 | use: ['style-loader', 'css-loader'],
14 | },
15 | ],
16 | },
17 | performance: {
18 | hints: process.env.NODE_ENV === 'production' ? 'warning' : false,
19 | },
20 | };
21 |
--------------------------------------------------------------------------------
/tutorials/09_get_account_comments/index.js:
--------------------------------------------------------------------------------
1 | const Koa = require('koa');
2 | const app = new Koa();
3 | const serve = require('koa-static');
4 | app.use(serve('./public'));
5 |
6 | app.listen(3000);
7 |
8 | console.log('listening on port 3000');
9 |
--------------------------------------------------------------------------------
/tutorials/09_get_account_comments/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "09_get_account_comments",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "webpack && node ./index.js",
8 | "test": "echo \"Error: no test specified\" && exit 1",
9 | "dev-server":
10 | "./node_modules/.bin/webpack-dev-server --mode development --content-base ./public --port 3000"
11 | },
12 | "author": "",
13 | "license": "ISC",
14 | "dependencies": {
15 | "bootstrap": "^4.1.3",
16 | "dsteem": "^0.10.1",
17 | "koa": "^2.5.3",
18 | "koa-static": "^5.0.0",
19 | "remarkable": "^1.7.1"
20 | },
21 | "devDependencies": {
22 | "css-loader": "^1.0.0",
23 | "style-loader": "^0.23.1",
24 | "webpack": "^4.20.2",
25 | "webpack-cli": "^3.1.2",
26 | "webpack-dev-server": "^3.1.9"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/tutorials/09_get_account_comments/public/app.js:
--------------------------------------------------------------------------------
1 | const dsteem = require('dsteem');
2 | let opts = {};
3 | //connect to production server
4 | opts.addressPrefix = 'STM';
5 | opts.chainId =
6 | '0000000000000000000000000000000000000000000000000000000000000000';
7 | //connect to server which is connected to the network/production
8 | const client = new dsteem.Client('https://api.steemit.com');
9 |
10 | const Remarkable = require('remarkable');
11 | const md = new Remarkable({ html: true, linkify: true });
12 |
13 | //fetch list of comments for certain account
14 | async function main() {
15 | const query = '/@steemitblog/comments';
16 | client.database
17 | .call('get_state', [query])
18 | .then(result => {
19 | console.log(result);
20 | if (
21 | !(
22 | Object.keys(result.content).length === 0 &&
23 | result.content.constructor === Object
24 | )
25 | ) {
26 | var comments = [];
27 | Object.keys(result.content).forEach(key => {
28 | const comment = result.content[key];
29 | const parent_author = comment.parent_author;
30 | const parent_permlink = comment.parent_permlink;
31 | const created = new Date(comment.created).toDateString();
32 | const body = md.render(comment.body);
33 | const netvotes = comment.net_votes;
34 | comments.push(
35 | `\
36 |
\
37 |
@${comment.author} \
38 | ${created} \
39 | \
40 |
${body}
\
41 |
▲ ${netvotes}, Replied to: @${parent_author}/${parent_permlink} \
42 |
`
43 | );
44 | });
45 | document.getElementById('comments').style.display = 'block';
46 | document.getElementById('comments').innerHTML = comments.join(
47 | ''
48 | );
49 | }
50 | })
51 | .catch(err => {
52 | console.log(err);
53 | alert('Error occured, please reload the page');
54 | });
55 | }
56 | //catch error messages
57 | main().catch(console.error);
58 |
--------------------------------------------------------------------------------
/tutorials/09_get_account_comments/public/index.css:
--------------------------------------------------------------------------------
1 | #comments img,
2 | #comments iframe {
3 | max-width: 100%;
4 | }
5 |
--------------------------------------------------------------------------------
/tutorials/09_get_account_comments/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Get account comments
4 |
5 |
6 |
7 |
8 |
Comments by @steemitblog
9 |
10 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/tutorials/09_get_account_comments/public/style.scss:
--------------------------------------------------------------------------------
1 | import 'bootstrap/dist/css/bootstrap.min.css'
2 | import './index.css'
--------------------------------------------------------------------------------
/tutorials/09_get_account_comments/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | module.exports = {
3 | entry: ['./public/app.js', './public/style.scss'],
4 | output: {
5 | path: path.resolve(__dirname, 'public'),
6 | filename: 'bundle.js',
7 | },
8 | devtool: 'source-map',
9 | module: {
10 | rules: [
11 | {
12 | test: /\.css$/,
13 | use: ['style-loader', 'css-loader'],
14 | },
15 | ],
16 | },
17 | performance: {
18 | hints: process.env.NODE_ENV === 'production' ? 'warning' : false,
19 | },
20 | };
21 |
--------------------------------------------------------------------------------
/tutorials/10_submit_post/index.js:
--------------------------------------------------------------------------------
1 | const Koa = require('koa');
2 | const app = new Koa();
3 | const serve = require('koa-static');
4 | app.use(serve('./public'));
5 |
6 | app.listen(3000);
7 |
8 | console.log('listening on port 3000');
9 |
--------------------------------------------------------------------------------
/tutorials/10_submit_post/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "10_submit_post",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "webpack && node ./index.js",
8 | "test": "echo \"Error: no test specified\" && exit 1",
9 | "dev-server":
10 | "./node_modules/.bin/webpack-dev-server --mode development --content-base ./public --port 3000"
11 | },
12 | "author": "",
13 | "license": "ISC",
14 | "dependencies": {
15 | "bootstrap": "^4.1.3",
16 | "dsteem": "^0.10.1",
17 | "koa": "^2.5.3",
18 | "koa-static": "^5.0.0",
19 | "remarkable": "^1.7.1"
20 | },
21 | "devDependencies": {
22 | "css-loader": "^1.0.0",
23 | "style-loader": "^0.23.1",
24 | "webpack": "^4.20.2",
25 | "webpack-cli": "^3.1.2",
26 | "webpack-dev-server": "^3.1.9"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/tutorials/10_submit_post/public/app.js:
--------------------------------------------------------------------------------
1 | import { Client, PrivateKey } from 'dsteem';
2 | import { Testnet as NetConfig } from '../../configuration'; //A Steem Testnet. Replace 'Testnet' with 'Mainnet' to connect to the main Steem blockchain.
3 |
4 | let opts = { ...NetConfig.net };
5 |
6 | //connect to server which is connected to the network/testnet
7 | const client = new Client(NetConfig.url, opts);
8 |
9 | //submit post function
10 | window.submitPost = async () => {
11 | //get private key
12 | const privateKey = PrivateKey.fromString(
13 | document.getElementById('postingKey').value
14 | );
15 | //get account name
16 | const account = document.getElementById('username').value;
17 | //get title
18 | const title = document.getElementById('title').value;
19 | //get body
20 | const body = document.getElementById('body').value;
21 | //get tags and convert to array list
22 | const tags = document.getElementById('tags').value;
23 | const taglist = tags.split(' ');
24 | //make simple json metadata including only tags
25 | const json_metadata = JSON.stringify({ tags: taglist });
26 | //generate random permanent link for post
27 | const permlink = Math.random()
28 | .toString(36)
29 | .substring(2);
30 |
31 | const payload = {
32 | author: account,
33 | body: body,
34 | json_metadata: json_metadata,
35 | parent_author: '',
36 | parent_permlink: taglist[0],
37 | permlink: permlink,
38 | title: title,
39 | };
40 | console.log('client.broadcast.comment:', payload);
41 | client.broadcast.comment(payload, privateKey).then(
42 | function(result) {
43 | console.log('response:', result);
44 | document.getElementById('title').value = '';
45 | document.getElementById('body').value = '';
46 | document.getElementById('tags').value = '';
47 | document.getElementById('postLink').style.display = 'block';
48 | document.getElementById(
49 | 'postLink'
50 | ).innerHTML = `Included in block: ${
51 | result.block_num
52 | }
Check post here `;
55 | },
56 | function(error) {
57 | console.error(error);
58 | }
59 | );
60 | };
61 |
62 | window.onload = () => {
63 | const account = NetConfig.accounts[0];
64 | document.getElementById('username').value = account.address;
65 | document.getElementById('postingKey').value = account.privPosting;
66 | };
67 |
--------------------------------------------------------------------------------
/tutorials/10_submit_post/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Submit post
4 |
5 |
6 |
7 |
19 |
20 |
--------------------------------------------------------------------------------
/tutorials/10_submit_post/public/style.scss:
--------------------------------------------------------------------------------
1 | import 'bootstrap/dist/css/bootstrap.min.css'
--------------------------------------------------------------------------------
/tutorials/10_submit_post/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | module.exports = {
3 | entry: ['./public/app.js', './public/style.scss'],
4 | output: {
5 | path: path.resolve(__dirname, 'public'),
6 | filename: 'bundle.js',
7 | },
8 | devtool: 'source-map',
9 | module: {
10 | rules: [
11 | {
12 | test: /\.css$/,
13 | use: ['style-loader', 'css-loader'],
14 | },
15 | ],
16 | },
17 | performance: {
18 | hints: process.env.NODE_ENV === 'production' ? 'warning' : false,
19 | },
20 | };
21 |
--------------------------------------------------------------------------------
/tutorials/11_submit_comment_reply/images/comment_reply_successful_console_output.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/steemit/devportal-tutorials-js/f20dcc475775def4488daf5b66b5f1bd35bdb8c5/tutorials/11_submit_comment_reply/images/comment_reply_successful_console_output.png
--------------------------------------------------------------------------------
/tutorials/11_submit_comment_reply/images/comment_reply_user_input.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/steemit/devportal-tutorials-js/f20dcc475775def4488daf5b66b5f1bd35bdb8c5/tutorials/11_submit_comment_reply/images/comment_reply_user_input.png
--------------------------------------------------------------------------------
/tutorials/11_submit_comment_reply/index.js:
--------------------------------------------------------------------------------
1 | const Koa = require('koa');
2 | const app = new Koa();
3 | const serve = require('koa-static');
4 | app.use(serve('./public'));
5 |
6 | app.listen(3000);
7 |
8 | console.log('listening on port 3000');
9 |
--------------------------------------------------------------------------------
/tutorials/11_submit_comment_reply/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "11_submit_comment_reply",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "webpack && node ./index.js",
8 | "test": "echo \"Error: no test specified\" && exit 1",
9 | "dev-server": "./node_modules/.bin/webpack-dev-server --mode development --content-base ./public --port 3000"
10 | },
11 | "author": "",
12 | "license": "ISC",
13 | "dependencies": {
14 | "bootstrap": "^4.1.3",
15 | "dsteem": "^0.10.1",
16 | "koa": "^2.5.3",
17 | "koa-static": "^5.0.0",
18 | "remarkable": "^1.7.1"
19 | },
20 | "devDependencies": {
21 | "css-loader": "^1.0.0",
22 | "style-loader": "^0.23.1",
23 | "webpack": "^4.20.2",
24 | "webpack-cli": "^3.1.2",
25 | "webpack-dev-server": "^3.1.9"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tutorials/11_submit_comment_reply/public/app.js:
--------------------------------------------------------------------------------
1 | //Step 1.
2 | import { Client, PrivateKey } from 'dsteem';
3 | import { Testnet as NetConfig } from '../../configuration'; //A Steem Testnet. Replace 'Testnet' with 'Mainnet' to connect to the main Steem blockchain.
4 |
5 | let opts = { ...NetConfig.net };
6 |
7 | //connect to server which is connected to the network/testnet
8 | const client = new Client(NetConfig.url, opts);
9 |
10 | //Step 2. user fills in the values for 'parent_author' and 'parent_permlink'
11 | //Step 3. user adds content for the comment in the 'body' textarea
12 |
13 | //submit post function
14 | window.submitComment = async () => {
15 | //Step 4. get all values from the UI
16 |
17 | //get private key
18 | const privateKey = PrivateKey.fromString(
19 | document.getElementById('postingKey').value
20 | );
21 | //get account name
22 | const account = document.getElementById('username').value;
23 | //get body
24 | const body = document.getElementById('body').value;
25 | //get parent author permalink
26 | const parent_author = document.getElementById('parent_author').value;
27 | //get parent author permalink
28 | const parent_permlink = document.getElementById('parent_permlink').value;
29 |
30 | //generate random permanent link for post
31 | const permlink = Math.random()
32 | .toString(36)
33 | .substring(2);
34 |
35 | const payload = {
36 | author: account,
37 | title: '',
38 | body: body,
39 | parent_author: parent_author,
40 | parent_permlink: parent_permlink,
41 | permlink: permlink,
42 | json_metadata: '',
43 | };
44 |
45 | console.log('client.broadcast.comment payload:', payload);
46 | client.broadcast.comment(payload, privateKey).then(
47 | function(result) {
48 | console.log('client.broadcast.comment response', result);
49 | document.getElementById('postLink').style.display = 'block';
50 | document.getElementById(
51 | 'postLink'
52 | ).innerHTML = `Included in block: ${
53 | result.block_num
54 | }
Check post here `;
55 | },
56 | function(error) {
57 | console.error(error);
58 | }
59 | );
60 | };
61 |
62 | window.clearFields = function() {
63 | document.getElementById('body').value = '';
64 | document.getElementById('parent_author').value = '';
65 | document.getElementById('parent_permlink').value = '';
66 | };
67 |
68 | window.onload = () => {
69 | const account = NetConfig.accounts[0];
70 | document.getElementById('username').value = account.address;
71 | document.getElementById('postingKey').value = account.privPosting;
72 | };
73 |
--------------------------------------------------------------------------------
/tutorials/11_submit_comment_reply/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Submit post
4 |
5 |
6 |
7 |
20 |
21 |
--------------------------------------------------------------------------------
/tutorials/11_submit_comment_reply/public/style.scss:
--------------------------------------------------------------------------------
1 | import 'bootstrap/dist/css/bootstrap.min.css'
--------------------------------------------------------------------------------
/tutorials/11_submit_comment_reply/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | module.exports = {
3 | entry: ['./public/app.js', './public/style.scss'],
4 | output: {
5 | path: path.resolve(__dirname, 'public'),
6 | filename: 'bundle.js',
7 | },
8 | devtool: 'source-map',
9 | module: {
10 | rules: [
11 | {
12 | test: /\.css$/,
13 | use: ['style-loader', 'css-loader'],
14 | },
15 | ],
16 | },
17 | performance: {
18 | hints: process.env.NODE_ENV === 'production' ? 'warning' : false,
19 | },
20 | };
21 |
--------------------------------------------------------------------------------
/tutorials/12_edit_content_patching/index.js:
--------------------------------------------------------------------------------
1 | const Koa = require('koa');
2 | const app = new Koa();
3 | const serve = require('koa-static');
4 | app.use(serve('./public'));
5 |
6 | app.listen(3000);
7 |
8 | console.log('listening on port 3000');
9 |
--------------------------------------------------------------------------------
/tutorials/12_edit_content_patching/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "12_edit_content_patching",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "webpack && node ./index.js",
8 | "test": "echo \"Error: no test specified\" && exit 1",
9 | "dev-server":
10 | "./node_modules/.bin/webpack-dev-server --mode development --content-base ./public --port 3000"
11 | },
12 | "author": "",
13 | "license": "ISC",
14 | "dependencies": {
15 | "bootstrap": "^4.1.3",
16 | "diff-match-patch": "^1.0.4",
17 | "dsteem": "^0.10.1",
18 | "koa": "^2.5.3",
19 | "koa-static": "^5.0.0",
20 | "remarkable": "^1.7.1"
21 | },
22 | "devDependencies": {
23 | "css-loader": "^1.0.0",
24 | "style-loader": "^0.23.1",
25 | "webpack": "^4.20.2",
26 | "webpack-cli": "^3.1.2",
27 | "webpack-dev-server": "^3.1.9"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tutorials/12_edit_content_patching/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Submit edited post
4 |
5 |
6 |
7 |
21 |
22 |
--------------------------------------------------------------------------------
/tutorials/12_edit_content_patching/public/style.scss:
--------------------------------------------------------------------------------
1 | import 'bootstrap/dist/css/bootstrap.min.css'
--------------------------------------------------------------------------------
/tutorials/12_edit_content_patching/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | module.exports = {
3 | entry: ['./public/app.js', './public/style.scss'],
4 | output: {
5 | path: path.resolve(__dirname, 'public'),
6 | filename: 'bundle.js',
7 | },
8 | devtool: 'source-map',
9 | module: {
10 | rules: [
11 | {
12 | test: /\.css$/,
13 | use: ['style-loader', 'css-loader'],
14 | },
15 | ],
16 | },
17 | performance: {
18 | hints: process.env.NODE_ENV === 'production' ? 'warning' : false,
19 | },
20 | };
21 |
--------------------------------------------------------------------------------
/tutorials/13_stream_blockchain_transactions/index.js:
--------------------------------------------------------------------------------
1 | const Koa = require('koa');
2 | const app = new Koa();
3 | const serve = require('koa-static');
4 | app.use(serve('./public'));
5 |
6 | app.listen(3000);
7 |
8 | console.log('listening on port 3000');
9 |
--------------------------------------------------------------------------------
/tutorials/13_stream_blockchain_transactions/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "13_stream_blockchain_transactions",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "webpack && node ./index.js",
8 | "test": "echo \"Error: no test specified\" && exit 1",
9 | "dev-server":
10 | "./node_modules/.bin/webpack-dev-server --mode development --content-base ./public --port 3000"
11 | },
12 | "author": "",
13 | "license": "ISC",
14 | "dependencies": {
15 | "bootstrap": "^4.1.3",
16 | "diff-match-patch": "^1.0.4",
17 | "dsteem": "^0.10.1",
18 | "koa": "^2.5.3",
19 | "koa-static": "^5.0.0",
20 | "remarkable": "^1.7.1"
21 | },
22 | "devDependencies": {
23 | "css-loader": "^1.0.0",
24 | "style-loader": "^0.23.1",
25 | "webpack": "^4.20.2",
26 | "webpack-cli": "^3.1.2",
27 | "webpack-dev-server": "^3.1.9"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tutorials/13_stream_blockchain_transactions/public/app.js:
--------------------------------------------------------------------------------
1 | const dsteem = require('dsteem');
2 |
3 | let opts = {};
4 |
5 | //connect to production server
6 | opts.addressPrefix = 'STM';
7 | opts.chainId =
8 | '0000000000000000000000000000000000000000000000000000000000000000';
9 |
10 | //connect to server which is connected to the network/production
11 | const client = new dsteem.Client('https://api.steemit.com');
12 |
13 | let stream;
14 | let state;
15 | let blocks = [];
16 | //start stream
17 | async function main() {
18 | stream = client.blockchain.getBlockStream();
19 | stream
20 | .on('data', function(block) {
21 | //console.log(block);
22 | blocks.unshift(
23 | `Block id: ${
24 | block.block_id
25 | } Transactions in this block: ${
26 | block.transactions.length
27 | } Witness: ${
28 | block.witness
29 | }
Timestamp: ${
30 | block.timestamp
31 | }
`
32 | );
33 | document.getElementById('blockList').innerHTML = blocks.join('');
34 | })
35 | .on('end', function() {
36 | // done
37 | console.log('END');
38 | });
39 | }
40 | //catch error messages
41 | main().catch(console.error);
42 |
43 | //pause stream
44 | window.pauseStream = async () => {
45 | state = stream.pause();
46 | };
47 |
48 | //resume stream
49 | window.resumeStream = async () => {
50 | state = state.resume();
51 | };
52 |
--------------------------------------------------------------------------------
/tutorials/13_stream_blockchain_transactions/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Stream Steem blockchain
4 |
5 |
6 |
7 |
8 |
Stream Steem blocks and transactions
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/tutorials/13_stream_blockchain_transactions/public/style.scss:
--------------------------------------------------------------------------------
1 | import 'bootstrap/dist/css/bootstrap.min.css'
--------------------------------------------------------------------------------
/tutorials/13_stream_blockchain_transactions/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | module.exports = {
3 | entry: ['./public/app.js', './public/style.scss'],
4 | output: {
5 | path: path.resolve(__dirname, 'public'),
6 | filename: 'bundle.js',
7 | },
8 | devtool: 'source-map',
9 | module: {
10 | rules: [
11 | {
12 | test: /\.css$/,
13 | use: ['style-loader', 'css-loader'],
14 | },
15 | ],
16 | },
17 | performance: {
18 | hints: process.env.NODE_ENV === 'production' ? 'warning' : false,
19 | },
20 | };
21 |
--------------------------------------------------------------------------------
/tutorials/14_reblogging_post/index.js:
--------------------------------------------------------------------------------
1 | const Koa = require('koa');
2 | const app = new Koa();
3 | const serve = require('koa-static');
4 | app.use(serve('./public'));
5 |
6 | app.listen(3000);
7 |
8 | console.log('listening on port 3000');
9 |
--------------------------------------------------------------------------------
/tutorials/14_reblogging_post/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "14_reblogging_post",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "webpack && node ./index.js",
8 | "test": "echo \"Error: no test specified\" && exit 1",
9 | "dev-server":
10 | "./node_modules/.bin/webpack-dev-server --mode development --content-base ./public --port 3000"
11 | },
12 | "author": "",
13 | "license": "ISC",
14 | "dependencies": {
15 | "bootstrap": "^4.1.3",
16 | "dsteem": "^0.10.1",
17 | "koa": "^2.5.3",
18 | "koa-static": "^5.0.0",
19 | "remarkable": "^1.7.1"
20 | },
21 | "devDependencies": {
22 | "css-loader": "^1.0.0",
23 | "style-loader": "^0.23.1",
24 | "webpack": "^4.20.2",
25 | "webpack-cli": "^3.1.2",
26 | "webpack-dev-server": "^3.1.9"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/tutorials/14_reblogging_post/public/app.js:
--------------------------------------------------------------------------------
1 | import { Client, PrivateKey } from 'dsteem';
2 |
3 | //define network parameters
4 | let opts = {};
5 | opts.addressPrefix = 'STM';
6 | opts.chainId =
7 | '0000000000000000000000000000000000000000000000000000000000000000';
8 | //connect to a Steem node. This is currently setup on production, but we recommend using a testnet like https://testnet.steem.vc
9 | const client = new Client('https://api.steemit.com', opts);
10 | window.client = client;
11 |
12 | //This is a convenience function for the UI.
13 | window.autofillAuthorAndPermlink = function(el) {
14 | document.getElementById('theAuthor').value = el.dataset.author;
15 | document.getElementById('thePermLink').value = el.dataset.permlink;
16 | };
17 |
18 | function fetchBlog() {
19 | const query = {
20 | tag: 'steemitblog',
21 | limit: 5,
22 | };
23 |
24 | client.database
25 | .getDiscussions('blog', query) //get a list of posts for easy resteeming.
26 | .then(result => {
27 | //when the response comes back ...
28 | const postList = [];
29 | console.log('Listing blog posts by ' + query.tag);
30 | result.forEach(post => {
31 | //... loop through the posts ...
32 | const author = post.author;
33 | const permlink = post.permlink;
34 | console.log(author, permlink, post);
35 | postList.push(
36 | // and render the table rows
37 | `Autofill ${author} ${permlink} `
38 | );
39 | });
40 |
41 | document.getElementById('postList').innerHTML = postList.join('');
42 | })
43 | .catch(err => {
44 | console.error(err);
45 | alert('Error occured' + err);
46 | });
47 | }
48 |
49 | //this function will execute when the "Resteem!" button is clicked
50 | window.submitPost = async () => {
51 | resteemOutput('preparing to submit');
52 | //get private key
53 | try {
54 | const privateKey = PrivateKey.from(
55 | document.getElementById('postingKey').value
56 | );
57 |
58 | //get account name
59 | const myAccount = document.getElementById('username').value;
60 | //get blog author
61 | const theAuthor = document.getElementById('theAuthor').value;
62 | //get blog permLink
63 | const thePermLink = document.getElementById('thePermLink').value;
64 |
65 | const jsonOp = JSON.stringify([
66 | 'reblog',
67 | {
68 | account: myAccount,
69 | author: theAuthor,
70 | permlink: thePermLink,
71 | },
72 | ]);
73 |
74 | const data = {
75 | id: 'follow',
76 | json: jsonOp,
77 | required_auths: [],
78 | required_posting_auths: [myAccount],
79 | };
80 | resteemOutput('resteeming:\n', JSON.stringify(data, 2));
81 | console.log('resteeming:', data);
82 | client.broadcast.json(data, privateKey).then(
83 | function(result) {
84 | resteemOutput(result);
85 | console.log('resteem result: ', result);
86 | },
87 | function(error) {
88 | console.error(error);
89 | }
90 | );
91 | } catch (e) {
92 | resteemOutput(e.message);
93 | console.log(e);
94 | }
95 | };
96 |
97 | function resteemOutput(output) {
98 | document.getElementById('results').innerText = output;
99 | }
100 |
101 | window.onload = async () => {
102 | fetchBlog();
103 | };
104 |
--------------------------------------------------------------------------------
/tutorials/14_reblogging_post/public/index.css:
--------------------------------------------------------------------------------
1 | td {
2 | }
3 | table {
4 | }
5 |
--------------------------------------------------------------------------------
/tutorials/14_reblogging_post/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Re-blog post
4 |
5 |
6 |
7 |
8 |
Re-blog post
9 |
10 | This tutorial encourages experimentation. You can choose from one of the Trending posts that appear below,
11 | or you can type in your own author and permlink to re-steem. Please note that by default this tutorial
12 | is configured to run on the main network; any re-steems go onto the chain forever! If you want to play
13 | with this tutorial in a safer environment, we suggest using a testnet ex:https://testnet.steem.vc.
14 |
15 |
Trending posts
16 |
17 |
18 |
19 |
20 | Resteem
21 |
22 |
23 | Author
24 |
25 |
26 | Permlink
27 |
28 |
29 |
30 |
31 |
32 |
33 | Loading...
34 |
35 |
36 |
37 |
38 |
Data required to resteem a post
39 |
(You have to provide the account that will do the resteeming)
40 | Account username that will resteem:
41 | Posting private key:
42 | The author to resteem:
43 | The Post to resteem:
44 |
45 |
46 |
47 |
Resteem Results
48 | (see console log for actual object)
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/tutorials/14_reblogging_post/public/style.scss:
--------------------------------------------------------------------------------
1 | import 'bootstrap/dist/css/bootstrap.min.css'
2 | import './index.css'
--------------------------------------------------------------------------------
/tutorials/14_reblogging_post/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | module.exports = {
3 | entry: ['./public/app.js', './public/style.scss'],
4 | output: {
5 | path: path.resolve(__dirname, 'public'),
6 | filename: 'bundle.js',
7 | },
8 | devtool: 'source-map',
9 | module: {
10 | rules: [
11 | {
12 | test: /\.css$/,
13 | use: ['style-loader', 'css-loader'],
14 | },
15 | ],
16 | },
17 | performance: {
18 | hints: process.env.NODE_ENV === 'production' ? 'warning' : false,
19 | },
20 | };
21 |
--------------------------------------------------------------------------------
/tutorials/15_search_accounts/README.md:
--------------------------------------------------------------------------------
1 | # Search Account Names
2 |
3 | _By the end of this tutorial you should know how to call a list of user names from the steem blockchain_
4 |
5 | This tutorial will show the method of capturing a queried user name, matching that to the steem database and then displaying the matching names. This tutorial will be run on the `production server`.
6 |
7 | ## Intro
8 |
9 | We are using the `call` function provided by the `dsteem` library to pull user names from the steem blockchain. The information being pulled is dependent on two variables:
10 |
11 | 1. The max number of user names that needs to be displayed by the search
12 | 2. The string representing the first characters of the user name you are searching for
13 |
14 | A simple HTML interface is used to both capture the string query as well as display the completed search. The layout can be found in the "index.html" file.
15 |
16 | ## Steps
17 |
18 | 1. [**Configure connection**](#configure_connection) Configuration of `dsteem` to use the proper connection and network.
19 | 2. [**Collecting input variables**](#collecting_input_variables) Assigning and collecting the necessary variables
20 | 3. [**Blockchain query**](#blockchain_query) Finding the data on the blockchain based on the inputs
21 | 4. [**Output**](#output) Displaying query results
22 |
23 |
24 | #### 1. **Configure connection**
25 |
26 | Below we have `dsteem` pointing to the production network with the proper chainId, addressPrefix, and endpoint. There is a `public/app.js` file which holds the Javascript segment of this tutorial. In the first few lines we define the configured library and packages:
27 |
28 | ```javascript
29 | const dsteem = require('dsteem');
30 | let opts = {};
31 | //connect to production server
32 | opts.addressPrefix = 'STM';
33 | opts.chainId =
34 | '0000000000000000000000000000000000000000000000000000000000000000';
35 | //connect to server which is connected to the network/production
36 | const client = new dsteem.Client('https://api.steemit.com');
37 | ```
38 |
39 | #### 2. **Collecting input variables**
40 |
41 | Next we assign the max number of lines that will be returned by the query. We also use `getElementById` to retrieve the requested user name for searching from the HTML interface. The `max` value can very easily also be attained from the HTML side simply by adding another input line in `index.html` and a second `getElementById` line.
42 |
43 | ```javascript
44 | const max = 10;
45 | window.submitAcc = async () => {
46 | const accSearch = document.getElementById("username").value;
47 | ```
48 |
49 | #### 3. **Blockchain query**
50 |
51 | The next step is to pull the user names from the blockchain that matches the "username" variable that was retrieved. This is done using the `database.call` function and assigning the result to an array.
52 |
53 | ```javascript
54 | const _accounts = await client.database.call('lookup_accounts',[accSearch, max]);
55 | console.log(`_accounts:`, _accounts);
56 | ```
57 |
58 | #### 4. **Output**
59 |
60 | Finally we create a list from the "_accounts" array generated in step 3.
61 |
62 | ```javascript
63 | document.getElementById('accList').innerHTML = _accounts.join(' ');
64 | }
65 | ```
66 |
67 | ## To run this tutorial
68 |
69 | 1. clone this repo
70 | 2. `cd tutorials/15_search_accounts`
71 | 3. `npm i`
72 | 4. `npm run dev-server` or `npm run start`
73 | 5. After a few moments, the server should be running at [http://localhost:3000/](http://localhost:3000/)
74 |
--------------------------------------------------------------------------------
/tutorials/15_search_accounts/index.js:
--------------------------------------------------------------------------------
1 | const Koa = require('koa');
2 | const app = new Koa();
3 | const serve = require('koa-static');
4 | app.use(serve('./public'));
5 |
6 | app.listen(3000);
7 |
8 | console.log('listening on port 3000');
9 |
--------------------------------------------------------------------------------
/tutorials/15_search_accounts/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "15_search_accounts",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "webpack && node ./index.js",
8 | "test": "echo \"Error: no test specified\" && exit 1",
9 | "dev-server": "./node_modules/.bin/webpack-dev-server --mode development --content-base ./public --port 3000"
10 | },
11 | "author": "",
12 | "license": "ISC",
13 | "dependencies": {
14 | "bootstrap": "^4.1.3",
15 | "dsteem": "^0.10.1",
16 | "koa": "^2.5.3",
17 | "koa-static": "^5.0.0",
18 | "remarkable": "^1.7.1"
19 | },
20 | "devDependencies": {
21 | "css-loader": "^1.0.0",
22 | "style-loader": "^0.23.1",
23 | "webpack": "^4.20.2",
24 | "webpack-cli": "^3.1.2",
25 | "webpack-dev-server": "^3.1.9"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tutorials/15_search_accounts/public/app.js:
--------------------------------------------------------------------------------
1 | const dsteem = require('dsteem');
2 | let opts = {};
3 | //connect to production server
4 | opts.addressPrefix = 'STM';
5 | opts.chainId =
6 | '0000000000000000000000000000000000000000000000000000000000000000';
7 | //connect to server which is connected to the network/production
8 | const client = new dsteem.Client('https://api.steemit.com');
9 |
10 |
11 |
12 | //submitAcc function from html input
13 | const max = 10;
14 | window.submitAcc = async () => {
15 | const accSearch = document.getElementById("username").value;
16 |
17 | const _accounts = await client.database.call('lookup_accounts',[accSearch, max]);
18 | console.log(`_accounts:`, _accounts);
19 |
20 | //disply list of account names with line breaks
21 | document.getElementById('accList').innerHTML = _accounts.join(' ');
22 | }
--------------------------------------------------------------------------------
/tutorials/15_search_accounts/public/index.css:
--------------------------------------------------------------------------------
1 | #replies img,
2 | #replies iframe {
3 | max-width: 100%;
4 | }
5 |
--------------------------------------------------------------------------------
/tutorials/15_search_accounts/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Find Account
4 |
5 |
6 |
7 |
8 |
Enter Account Name to search
9 |
10 |
11 |
Matching Account Names:
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/tutorials/15_search_accounts/public/style.scss:
--------------------------------------------------------------------------------
1 | import 'bootstrap/dist/css/bootstrap.min.css'
2 | import './index.css'
--------------------------------------------------------------------------------
/tutorials/15_search_accounts/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | module.exports = {
3 | entry: ['./public/app.js', './public/style.scss'],
4 | output: {
5 | path: path.resolve(__dirname, 'public'),
6 | filename: 'bundle.js',
7 | },
8 | devtool: 'source-map',
9 | module: {
10 | rules: [
11 | {
12 | test: /\.css$/,
13 | use: ['style-loader', 'css-loader'],
14 | },
15 | ],
16 | },
17 | performance: {
18 | hints: process.env.NODE_ENV === 'production' ? 'warning' : false,
19 | },
20 | };
21 |
--------------------------------------------------------------------------------
/tutorials/16_search_tags/README.md:
--------------------------------------------------------------------------------
1 | # Search for Tags
2 |
3 | _By the end of this tutorial you should know how to run a search for trending tags_
4 |
5 | This tutorial runs on the main Steem blockchain.
6 |
7 | ## Intro
8 |
9 | This tutorial will show the method of capturing a queried tag name and matching it to the steem database. We are using the `call` function provided by the `dsteem` library to pull tags from the steem blockchain. A simple HTML interface is used to both capture the string query as well as display the completed search.
10 |
11 | ## steps
12 |
13 | 1. [**Configure connection**](#configure-conn) Configuration of `dsteem` to use the proper connection and network.
14 | 2. [**Search input**](#search-input) Collecting the relevant search criteria
15 | 3. [**Run Search**](#run-search) Running the search on the blockchain
16 | 4. [**Output**](#output) Displaying the results of the search query
17 |
18 | #### 1. Configure connection