Commit 94a4e2f8 authored by Mahdi Yari's avatar Mahdi Yari

Merge branch 'fix-browserbuild-readme-1' into 'master'

Fix browserbuild and readme

See merge request !4
parents 3ebac6da c21cbf88
......@@ -11,7 +11,7 @@ build/Release
node_modules
.tern-port
dist/steem-tests.min.js*
dist/hive-tests.min.js*
# node-dist
.tern-port
.envrc
......
MIT License
Copyright (c) 2017 Steem.js
Copyright (c) 2017 Hive.js
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/steemit/steem-js/blob/master/LICENSE)
[![Steem.js channel on steemit.chat](https://img.shields.io/badge/chat-steemit.chat-1c56a4.svg)](https://steemit.chat/channel/steemjs)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://gitlab.syncad.com/hive/hive-js/blob/master/LICENSE)
# Steem.js
Steem.js the JavaScript API for Steem blockchain
# Hive.js
Hive.js the Official JavaScript API for Hive blockchain
# Documentation
- [Install](https://github.com/steemit/steem-js/tree/master/doc#install)
- [Browser](https://github.com/steemit/steem-js/tree/master/doc#browser)
- [Config](https://github.com/steemit/steem-js/tree/master/doc#config)
- [Database API](https://github.com/steemit/steem-js/tree/master/doc#api)
- [Subscriptions](https://github.com/steemit/steem-js/tree/master/doc#subscriptions)
- [Tags](https://github.com/steemit/steem-js/tree/master/doc#tags)
- [Blocks and transactions](https://github.com/steemit/steem-js/tree/master/doc#blocks-and-transactions)
- [Globals](https://github.com/steemit/steem-js/tree/master/doc#globals)
- [Keys](https://github.com/steemit/steem-js/tree/master/doc#keys)
- [Accounts](https://github.com/steemit/steem-js/tree/master/doc#accounts)
- [Market](https://github.com/steemit/steem-js/tree/master/doc#market)
- [Authority / validation](https://github.com/steemit/steem-js/tree/master/doc#authority--validation)
- [Votes](https://github.com/steemit/steem-js/tree/master/doc#votes)
- [Content](https://github.com/steemit/steem-js/tree/master/doc#content)
- [Witnesses](https://github.com/steemit/steem-js/tree/master/doc#witnesses)
- [Login API](https://github.com/steemit/steem-js/tree/master/doc#login)
- [Follow API](https://github.com/steemit/steem-js/tree/master/doc#follow-api)
- [Broadcast API](https://github.com/steemit/steem-js/tree/master/doc#broadcast-api)
- [Broadcast](https://github.com/steemit/steem-js/tree/master/doc#broadcast)
- [Auth](https://github.com/steemit/steem-js/tree/master/doc#auth)
- [Install](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#install)
- [Browser](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#browser)
- [Config](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#config)
- [Database API](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#api)
- [Subscriptions](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#subscriptions)
- [Tags](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#tags)
- [Blocks and transactions](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#blocks-and-transactions)
- [Globals](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#globals)
- [Keys](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#keys)
- [Accounts](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#accounts)
- [Market](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#market)
- [Authority / validation](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#authority--validation)
- [Votes](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#votes)
- [Content](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#content)
- [Witnesses](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#witnesses)
- [Login API](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#login)
- [Follow API](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#follow-api)
- [Broadcast API](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#broadcast-api)
- [Broadcast](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#broadcast)
- [Auth](https://gitlab.syncad.com/hive/hive-js/tree/master/doc#auth)
Here is full documentation:
https://github.com/steemit/steem-js/tree/master/doc
https://gitlab.syncad.com/hive/hive-js/tree/master/doc
## Browser
```html
<script src="./steem.min.js"></script>
<script src="./hive.min.js"></script>
<script>
steem.api.getAccounts(['ned', 'dan'], function(err, response){
hive.api.getAccounts(['mahdiyari', 'hiveio'], function(err, response){
console.log(err, response);
});
</script>
```
## CDN
https://cdn.jsdelivr.net/npm/steem/dist/steem.min.js<br/>
https://cdn.jsdelivr.net/npm/@hiveio/hive-js/dist/hive.min.js<br/>
```html
<script src="https://cdn.jsdelivr.net/npm/steem/dist/steem.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@hiveio/hive-js/dist/hive.min.js"></script>
```
## Webpack
[Please have a look at the webpack usage example.](https://github.com/steemit/steem-js/blob/master/examples/webpack-example)
[Please have a look at the webpack usage example.](https://gitlab.syncad.com/hive/hive-js/blob/master/examples/webpack-example)
## Server
## Install
```
$ npm install steem --save
$ npm install @hiveio/hive-js --save
```
## RPC Servers
https://api.steemit.com By Default<br/>
https://node.steem.ws<br/>
https://this.piston.rocks<br/>
https://api.hive.blog By Default<br/>
https://anyx.io<br/>
https://api.openhive.network<br/>
https://api.hivekings.com<br/>
https://api.pharesim.me<br/>
https://hived.privex.io<br/>
https://rpc.ausbit.dev<br/>
https://rpc.esteem.app<br/>
<sub>[List of Hive nodes](https://hivekings.com/nodes)</sub><br/>
## Examples
### Broadcast Vote
```js
var steem = require('steem');
var hive = require('@hiveio/hive-js');
var wif = steem.auth.toWif(username, password, 'posting');
steem.broadcast.vote(wif, voter, author, permlink, weight, function(err, result) {
var wif = hive.auth.toWif(username, password, 'posting');
hive.broadcast.vote(wif, voter, author, permlink, weight, function(err, result) {
console.log(err, result);
});
```
### Get Accounts
```js
steem.api.getAccounts(['ned', 'dan'], function(err, result) {
hive.api.getAccounts(['mahdiyari', 'hiveio'], function(err, result) {
console.log(err, result);
});
```
### Get State
```js
steem.api.getState('/trends/funny', function(err, result) {
hive.api.getState('/trends/funny', function(err, result) {
console.log(err, result);
});
```
### Reputation Formatter
```js
var reputation = steem.formatter.reputation(user.reputation);
var reputation = hive.formatter.reputation(user.reputation);
console.log(reputation);
```
### Steem Testnet
Steem-js requires some configuration to work on the public Steem testnet.
### Hive Testnet
Hive-js requires some configuration to work on the public Hive testnet.
You need to set two Steem API options, `address_prefix` and `chain_id`.
You need to set two Hive API options, `address_prefix` and `chain_id`.
```js
steem.api.setOptions({
hive.api.setOptions({
address_prefix: 'TST',
chain_id: '46d82ab7d8db682eb1959aed0ada039a6d49afa1602491f93dde9cac3e8e6c32',
useTestNet: true,
......@@ -107,7 +112,7 @@ steem.api.setOptions({
The Chain ID could change. If it does, it may not be reflected here, but will be documented on any testnet launch announcements.
## Contributions
Patches are welcome! Contributors are listed in the package.json file. Please run the tests before opening a pull request and make sure that you are passing all of them. If you would like to contribute, but don't know what to work on, check the issues list or on Steemit Chat channel #steemjs https://steemit.chat/channel/steemjs.
Patches are welcome! Contributors are listed in the package.json file. Please run the tests before opening a pull request and make sure that you are passing all of them.
## Issues
When you find issues, please report them!
......
This diff is collapsed.
const steem = require('../lib');
const hive = require('../lib');
/* Generate private active WIF */
const username = process.env.STEEM_USERNAME;
const password = process.env.STEEM_PASSWORD;
const privActiveWif = steem.auth.toWif(username, password, 'active');
const username = process.env.HIVE_USERNAME;
const password = process.env.HIVE_PASSWORD;
const privActiveWif = hive.auth.toWif(username, password, 'active');
/** Add posting key auth */
steem.broadcast.addKeyAuth({
hive.broadcast.addKeyAuth({
signingKey: privActiveWif,
username,
authorizedKey: 'STM88CPfhCmeEzCnvC1Cjc3DNd1DTjkMcmihih8SSxmm4LBqRq5Y9',
......
......@@ -2,22 +2,22 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Steem.js Broadcast</title>
<title>Hive.js Broadcast</title>
</head>
<body>
<script src="../dist/steem.min.js"></script>
<script src="../dist/hive.min.js"></script>
<script>
/** Configure your account */
var username = 'guest123';
var postingWif = '5JRaypasxMx1L97ZUX7YuC5Psb5EAbF821kkAGtBj7xCJFQcbLg';
/** Broadcast a vote */
steem.broadcast.vote(
hive.broadcast.vote(
postingWif,
username, // Voter
'firepower', // Author
'steemit-veni-vidi-vici-steemfest-2016-together-we-made-it-happen-thank-you-steemians', // Permlink
'hiveio', // Author
'announcing-the-launch-of-hive-blockchain', // Permlink
10000, // Weight (10000 = 100%)
function(err, result) {
console.log(err, result);
......@@ -27,7 +27,7 @@
/** Broadcast a comment */
var permlink = new Date().toISOString().replace(/[^a-zA-Z0-9]+/g, '').toLowerCase();
steem.broadcast.comment(
hive.broadcast.comment(
postingWif,
'siol', // Parent Author
'test', // Parent Permlink
......@@ -35,7 +35,7 @@
permlink, // Permlink
'', // Title
'This is a test!', // Body
{ tags: ['test'], app: 'steemjs/examples' }, // Json Metadata
{ tags: ['test'], app: 'hivejs/examples' }, // Json Metadata
function(err, result) {
console.log(err, result);
}
......@@ -44,7 +44,7 @@
/** Broadcast a post */
var permlink = new Date().toISOString().replace(/[^a-zA-Z0-9]+/g, '').toLowerCase();
steem.broadcast.comment(
hive.broadcast.comment(
postingWif,
'', // Leave parent author empty
'photography', // Main tag
......@@ -52,7 +52,7 @@
permlink + '-post', // Permlink
'This is just a test!', // Title
'Nothing to see here', // Body
{ tags: ['test'], app: 'steemjs/examples' }, // Json Metadata
{ tags: ['test'], app: 'hivejs/examples' }, // Json Metadata
function(err, result) {
console.log(err, result);
}
......@@ -60,7 +60,7 @@
/** Follow an user */
var follower = username; // Your username
var following = 'steemjs'; // User to follow
var following = 'hiveio'; // User to follow
var json = JSON.stringify(
['follow', {
......@@ -70,7 +70,7 @@
}]
);
steem.broadcast.customJson(
hive.broadcast.customJson(
postingWif,
[], // Required_auths
[follower], // Required Posting Auths
......@@ -90,7 +90,7 @@
}]
);
steem.broadcast.customJson(
hive.broadcast.customJson(
postingWif,
[], // Required_auths
[follower], // Required Posting Auths
......
const steem = require('../lib');
const hive = require('../lib');
const resultP = steem.api.getContentAsync('yamadapc', 'test-1-2-3-4-5-6-7-9');
const resultP = hive.api.getContentAsync('hiveio', 'announcing-the-launch-of-hive-blockchain');
resultP.then(result => console.log(result));
......@@ -2,19 +2,19 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Steem.js</title>
<title>Hive.js</title>
</head>
<body>
<script src="../dist/steem.min.js"></script>
<script src="../dist/hive.min.js"></script>
<script>
steem.api.getConfig(function(err, response){
hive.api.getConfig(function(err, response){
console.log(err, response);
});
steem.api.getAccounts(['ned', 'dan'], function(err, response){
hive.api.getAccounts(['hiveio', 'mahdiyari'], function(err, response){
console.log(err, response);
});
steem.api.getAccountCount(function(err, response){
hive.api.getAccountCount(function(err, response){
console.log(err, response);
});
</script>
......
const steem = require('../lib');
const hive = require('../lib');
const privWif1 = '5K2LA2ucS8b1GuFvVgZK6itKNE6fFMbDMX4GDtNHiczJESLGRd8';
const privWif2 = '5JRaypasxMx1L97ZUX7YuC5Psb5EAbF821kkAGtBj7xCJFQcbLg';
steem.broadcast.send({
hive.broadcast.send({
extensions: [],
operations: [
['vote', {
......
var steem = require('../lib');
var hive = require('../lib');
steem.api.getAccountCount(function(err, result) {
hive.api.getAccountCount(function(err, result) {
console.log(err, result);
});
steem.api.getAccounts(['dan'], function(err, result) {
hive.api.getAccounts(['hiveio'], function(err, result) {
console.log(err, result);
var reputation = steem.formatter.reputation(result[0].reputation);
var reputation = hive.formatter.reputation(result[0].reputation);
console.log(reputation);
});
steem.api.getState('trending/steemit', function(err, result) {
hive.api.getState('trending/hive', function(err, result) {
console.log(err, result);
});
steem.api.getFollowing('ned', 0, 'blog', 10, function(err, result) {
hive.api.getFollowing('hiveio', 0, 'blog', 10, function(err, result) {
console.log(err, result);
});
steem.api.getFollowers('dan', 0, 'blog', 10, function(err, result) {
hive.api.getFollowers('hiveio', 0, 'blog', 10, function(err, result) {
console.log(err, result);
});
steem.api.streamOperations(function(err, result) {
hive.api.streamOperations(function(err, result) {
console.log(err, result);
});
steem.api.getDiscussionsByActive({
hive.api.getDiscussionsByActive({
limit: 10,
start_author: 'thecastle',
start_permlink: 'this-week-in-level-design-1-22-2017'
......
......@@ -2,13 +2,13 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Steem.js Stream</title>
<title>Hive.js Stream</title>
</head>
<body>
<script src="../dist/steem.min.js"></script>
<script src="../dist/hive.min.js"></script>
<script>
steem.api.streamOperations(function (err, operations) {
hive.api.streamOperations(function (err, operations) {
operations.forEach(function (operation) {
console.log(operation);
});
......
const steem = require('../lib');
const hive = require('../lib');
const username = 'guest123';
const wif = '5JRaypasxMx1L97ZUX7YuC5Psb5EAbF821kkAGtBj7xCJFQcbLg';
steem
hive
.broadcast
.vote(
wif,
......
# `steem-js` webpack configuration example
This is a demo of `steem-js` and webpack usage targetting both the Web and
# `hive-js` webpack configuration example
This is a demo of `hive-js` and webpack usage targetting both the Web and
Node.js platforms.
## Compiling the example
......
{
"name": "steem-js-webpack-example",
"name": "hive-js-webpack-example",
"scripts": {
"build": "npm run build-web && npm run build-node",
"build-web": "webpack",
......@@ -10,6 +10,6 @@
"webpack": "^3.0.0"
},
"dependencies": {
"steem": "^0.5.20"
"hive": "^0.0.5"
}
}
const steem = require('steem/lib/browser');
const hive = require('hive/lib/browser');
console.log('Getting post content...');
const resultP = steem.api.getContentAsync('yamadapc', 'test-1-2-3-4-5-6-7-9');
const resultP = hive.api.getContentAsync('yamadapc', 'test-1-2-3-4-5-6-7-9');
resultP.then(result => console.log(result));
{
"name": "@hiveio/hive-js",
"version": "0.0.5",
"version": "0.1.0",
"description": "Hive.js the JavaScript API for Hive blockchain",
"main": "lib/index.js",
"scripts": {
......@@ -75,7 +75,8 @@
"Fabien (https://github.com/bonustrack)",
"James Calfee (https://github.com/jcalfee)",
"Nilesh Suthar (https://github.com/nil1511)",
"Pedro Tacla Yamada (https://github.com/yamadapc)"
"Pedro Tacla Yamada (https://github.com/yamadapc)",
"MahdiYari (https://github.com/mahdiyari)"
],
"directories": {
"doc": "doc",
......
......@@ -6,7 +6,7 @@ const config = require("./config");
const formatter = require("./formatter")(api);
const utils = require("./utils");
const steem = {
const hive = {
api,
auth,
memo,
......@@ -17,11 +17,11 @@ const steem = {
};
if (typeof window !== "undefined") {
window.steem = steem;
window.hive = hive;
}
if (typeof global !== "undefined") {
global.steem = steem;
global.hive = hive;
}
exports = module.exports = steem;
exports = module.exports = hive;
......@@ -174,17 +174,31 @@ module.exports = steemAPI => {
return out;
},
// Deprecated - Remove on future releases
vestToSteem: function(
vestingShares,
totalVestingShares,
totalVestingFundSteem
) {
console.warn('vestToSteem() is deprecated and will be removed in the future releases. Use vestToHive() instead.')
return (
parseFloat(totalVestingFundSteem) *
(parseFloat(vestingShares) / parseFloat(totalVestingShares))
);
},
// Same as vestToSteem
vestToHive: function(
vestingShares,
totalVestingShares,
totalVestingFundHive
) {
return (
parseFloat(totalVestingFundHive) *
(parseFloat(vestingShares) / parseFloat(totalVestingShares))
);
},
commentPermlink: function(parentAuthor, parentPermlink) {
const timeStr = new Date()
.toISOString()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment