README.md 61.3 KB
Newer Older
adcpm's avatar
adcpm committed
1
# Documentation
2

Primerz's avatar
Primerz committed
3
4
5
- [Install](#install)
- [Browser](#browser)
- [Config](#config)
adcpm's avatar
adcpm committed
6
- [JSON-RPC](#jsonrpc)
Primerz's avatar
Primerz committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
- [Database API](#api)
    - [Subscriptions](#subscriptions)
    - [Tags](#tags)
    - [Blocks and transactions](#blocks-and-transactions)
    - [Globals](#globals)
    - [Keys](#keys)
    - [Accounts](#accounts)
    - [Market](#market)
    - [Authority / validation](#authority--validation)
    - [Votes](#votes)
    - [Content](#content)
    - [Witnesses](#witnesses)
- [Login API](#login)
- [Follow API](#follow-api)
- [Broadcast API](#broadcast-api)
- [Broadcast](#broadcast)
- [Auth](#auth)
adcpm's avatar
adcpm committed
24
- [Formatter](#formatter)
Mahdi Yari's avatar
update    
Mahdi Yari committed
25
26
- [Utils](#utils)
- [Tutorials](#tutorials)
adcpm's avatar
adcpm committed
27

adcpm's avatar
adcpm committed
28
# Install
29
```
Mahdi Yari's avatar
Mahdi Yari committed
30
$ npm install @hiveio/hive-js --save
31
32
```

adcpm's avatar
adcpm committed
33
34
# Browser 
```html 
Mahdi Yari's avatar
Mahdi Yari committed
35
<script src="./hive.min.js"></script>
adcpm's avatar
adcpm committed
36
<script>
Mahdi Yari's avatar
Mahdi Yari committed
37
hive.api.getAccounts(['mahdiyari', 'hiveio'], function(err, response){
adcpm's avatar
adcpm committed
38
39
40
41
42
    console.log(err, response);
});
</script>
```

Mahdi Yari's avatar
update    
Mahdi Yari committed
43
44
45
46
47
48
## CDN
https://cdn.jsdelivr.net/npm/@hiveio/hive-js/dist/hive.min.js<br/>
```html
<script src="https://cdn.jsdelivr.net/npm/@hiveio/hive-js/dist/hive.min.js"></script>
```

Nilesh Suthar's avatar
Nilesh Suthar committed
49
## Config
Mahdi Yari's avatar
Mahdi Yari committed
50
Default config should work with Hive. However you can change default config.
Nilesh Suthar's avatar
Nilesh Suthar committed
51
52
as 
```js
Mahdi Yari's avatar
Mahdi Yari committed
53
54
hive.api.setOptions({ url: 'https://anyx.io' });
hive.config.set('address_prefix','STM');
Mahdi Yari's avatar
Mahdi Yari committed
55
hive.config.set('chain_id','beeab0de00000000000000000000000000000000000000000000000000000000');
Mahdi Yari's avatar
Mahdi Yari committed
56
hive.config.set('alternative_api_endpoints', ['https://api.hive.blog', 'https://anyx.io']);
Nilesh Suthar's avatar
Nilesh Suthar committed
57
```
Mahdi Yari's avatar
update    
Mahdi Yari committed
58

Nilesh Suthar's avatar
Nilesh Suthar committed
59
60
### set
```
Mahdi Yari's avatar
Mahdi Yari committed
61
hive.config.set('address_prefix','STM');
Nilesh Suthar's avatar
Nilesh Suthar committed
62
63
```
### get
adcpm's avatar
adcpm committed
64
```
Mahdi Yari's avatar
Mahdi Yari committed
65
hive.config.get('chain_id');
adcpm's avatar
adcpm committed
66
67
```

adcpm's avatar
adcpm committed
68
69
70
## JSON-RPC
Here is how to activate JSON-RPC transport:
```js
Mahdi Yari's avatar
Mahdi Yari committed
71
hive.api.setOptions({ url: 'https://api.hive.blog' });
adcpm's avatar
adcpm committed
72
73
```

Nilesh Suthar's avatar
Nilesh Suthar committed
74
75
# API

Mahdi Yari's avatar
Mahdi Yari committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
## API CALL
Can be used for all the possible API calls.

```js
hive.api.call(method, params, callback);
// or
hive.api.callAsync(method, params).then(res => {});
```

Example:
```js
hive.api.callAsync('condenser_api.get_accounts', [['mahdiyari']])
  .then((res) => console.log(res))
````

91
## Subscriptions
adcpm's avatar
adcpm committed
92

93
### Set Subscribe Callback
adcpm's avatar
adcpm committed
94
```
Mahdi Yari's avatar
Mahdi Yari committed
95
hive.api.setSubscribeCallback(callback, clearFilter, function(err, result) {
adcpm's avatar
adcpm committed
96
  console.log(err, result);
97
98
99
});
```
### Set Pending Transaction Callback
adcpm's avatar
adcpm committed
100
```
Mahdi Yari's avatar
Mahdi Yari committed
101
hive.api.setPendingTransactionCallback(cb, function(err, result) {
adcpm's avatar
adcpm committed
102
  console.log(err, result);
103
104
105
});
```
### Set Block Applied Callback
adcpm's avatar
adcpm committed
106
```
Mahdi Yari's avatar
Mahdi Yari committed
107
hive.api.setBlockAppliedCallback(cb, function(err, result) {
adcpm's avatar
adcpm committed
108
  console.log(err, result);
109
110
111
});
```
### Cancel All Subscriptions
adcpm's avatar
adcpm committed
112
```
Mahdi Yari's avatar
Mahdi Yari committed
113
hive.api.cancelAllSubscriptions(function(err, result) {
adcpm's avatar
adcpm committed
114
  console.log(err, result);
115
116
117
118
});
```

## Tags
adcpm's avatar
adcpm committed
119

120
### Get Trending Tags
Mahdi Yari's avatar
Mahdi Yari committed
121
Returns a list of the currently trending tags in descending order by value.
adcpm's avatar
adcpm committed
122
```
Mahdi Yari's avatar
Mahdi Yari committed
123
hive.api.getTrendingTags(afterTag, limit, function(err, result) {
adcpm's avatar
adcpm committed
124
  console.log(err, result);
125
126
});
```
Mahdi Yari's avatar
Mahdi Yari committed
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

|Parameter|Description|Datatype|Notes|
|---|---|---|---|
|afterTag|The name of the last tag to begin from|String|Use the empty string `''` to start the list. Subsequent calls can use the last tag name|
|limit|The maximum number of tags to return|Integer||
|function()|Your callback|function|Tip: use `console.log(err, result)` to see the result|

Call Example:
```js
hive.api.getTrendingTags('', 2, function(err, result) {
  console.log(err, result);
});
```

Return Example:
```js
[ { name: '', total_payouts: '37610793.383 SBD', net_votes: 4211122, top_posts: 411832, comments: 1344461, trending: '5549490701' },
  { name: 'life', total_payouts: '8722947.658 SBD', net_votes: 1498401, top_posts: 127103, comments: 54049, trending: '570954588' } ]
```

Using the Result:
Mahdi Yari's avatar
Mahdi Yari committed
148
```js
Mahdi Yari's avatar
Mahdi Yari committed
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Extract tags from the result into an array of tag name strings
var f = result.map(function(item) { return item.name; });
console.log(f);

// Get the last tag for subsequent calls to `getTrendingTags`
//   or use: f[f.length - 1]   if you used the extraction code above.
var lastKnownTag = result[result.length - 1].name;

// Use the last known tag to get the next group of tags
hive.api.TrendingTags(lastKnownTag, 2, function(err, result) {
  console.log(err, result);
});
```

See also: [getTrendingCategories](#get-trending-categories)

Mahdi Yari's avatar
Mahdi Yari committed
165
166
167
### Get Blog
Gets the last `limit` number of posts of `account` before the post with index `entryId`

Mahdi Yari's avatar
Mahdi Yari committed
168
```js
Mahdi Yari's avatar
Mahdi Yari committed
169
170
171
172
173
174
175
176
177
178
179
180
hive.api.getBlog(account, entryId, limit, callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|account|string|a hive username|
|entryId|number|a positive number - the index from which to start counting (the index is zero based)|
|limit|number|a positive number - the max count of posts to be returned|
|callback|function|function(err, data) {/*code*/}|


Call Example:
Mahdi Yari's avatar
Mahdi Yari committed
181
```js
Mahdi Yari's avatar
Mahdi Yari committed
182
183
184
185
186
187
188
189
190
191
hive.api.getBlog("username", 10, 3, function(err, data) {
	console.log(err, data);
});

// In this case we have a call to get [3] posts, the newest of which is the one with index [10]
//			(that's the 11-th post, because the post indexes are zero based)
// That means that the results will be posts [10, 9 and 8]
```

Return Example:
Mahdi Yari's avatar
Mahdi Yari committed
192
```js
Mahdi Yari's avatar
Mahdi Yari committed
193
194
[
  {
Mahdi Yari's avatar
Mahdi Yari committed
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
		blog:"username"
		comment: { /* Omited for simplicity */ }
		entry_id: 10
		reblog_on:"1970-01-01T00:00:00"
	},
	{
		blog:"username"
		comment: { /* Omited for simplicity */ }
		entry_id: 9
		reblog_on:"1970-01-01T00:00:00"
	},
	{
		blog:"username"
		comment: { /* Omited for simplicity */ }
		entry_id: 8
		reblog_on:"1970-01-01T00:00:00"
Mahdi Yari's avatar
Mahdi Yari committed
211
212
  }
]
Mahdi Yari's avatar
Mahdi Yari committed
213
214
```

Mahdi Yari's avatar
Mahdi Yari committed
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
### Get Blog Authors
Gets a list of all people who wrote in someones blog, along with how many times they wrote in that blog.

```js
hive.api.getBlogAuthors(blogAccount, callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|blogAccount|string|a hive username|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
hive.api.getBlogAuthors("username", function(err, data) {
	console.log(err, data);
});
```

Return Example:
```js
[ [ 'username1', 1 ],
  [ 'username2', 1 ],
  [ 'username3', 3 ],
  [ 'username4', 2 ],
  [ 'username5', 1 ] ]
```

Mahdi Yari's avatar
Mahdi Yari committed
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
### Get Blog Entries
Gets the last `limit` number of posts of `account` before the post with index `entryId`
Very similar to hive.api.getBlog but with much simpler result objects

```js
hive.api.getBlogEntries(account, entryId, limit, callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|account|string|a hive username|
|entryId|number|a positive number - the index from which to start counting (the index is zero based)|
|limit|number|a positive number - the max count of posts to be returned|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
hive.api.getBlogEntries("username", 10, 3, function(err, data) {
	console.log(err, data);
});

// In this case we have a call to get [3] posts, the newest of which is the one with index [10]
//			(that's the 11-th post, because the post indexes are zero based)
// That means that the results will be posts [10, 9 and 8]
```

Return Example:
```js
[ { author: 'username',
    permlink: 'post-permlink-10',
    blog: 'username',
    reblog_on: '1970-01-01T00:00:00',
    entry_id: 10 },
  { author: 'username',
    permlink: 'post-permlink-9',
    blog: 'username',
    reblog_on: '1970-01-01T00:00:00',
    entry_id: 9 },
  { author: 'username',
    permlink: 'post-permlink-8',
    blog: 'username',
    reblog_on: '1970-01-01T00:00:00',
    entry_id: 8 } ]
```

290
### Get Discussions By Trending
291
292
Gets the hive posts as they would be shown in the trending tab of hive.blog.

Mahdi Yari's avatar
Mahdi Yari committed
293
```js
Mahdi Yari's avatar
Mahdi Yari committed
294
hive.api.getDiscussionsByTrending(query, function(err, result) {
adcpm's avatar
adcpm committed
295
  console.log(err, result);
296
297
});
```
298
299
300
301
302
303
304
305
306

|Parameter|Datatype|Description|
|---------|--------|-----------|
|query|object|an object containing different options for querying, like 'limit' and 'tag'|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
Mahdi Yari's avatar
Mahdi Yari committed
307
308
var query = { limit : 3, tag : "hive" };
hive.api.getDiscussionsByTrending30(query, function(err, data) {
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
	console.log(err, data);
});

// NOTE! The default limit is 0. Not setting a limit will get you an empty result.
```

Return Example:
```js
// the result is an array of big objects representing the comments

 [ { /* ommited for simplicity */ },
   { /* ommited for simplicity */ },
   { /* ommited for simplicity */ } ]
```

324
### Get Discussions By Created
adcpm's avatar
adcpm committed
325
```
Mahdi Yari's avatar
Mahdi Yari committed
326
hive.api.getDiscussionsByCreated(query, function(err, result) {
adcpm's avatar
adcpm committed
327
  console.log(err, result);
328
329
330
});
```
### Get Discussions By Active
adcpm's avatar
adcpm committed
331
```
Mahdi Yari's avatar
Mahdi Yari committed
332
hive.api.getDiscussionsByActive(query, function(err, result) {
adcpm's avatar
adcpm committed
333
  console.log(err, result);
334
335
336
});
```
### Get Discussions By Cashout
adcpm's avatar
adcpm committed
337
```
Mahdi Yari's avatar
Mahdi Yari committed
338
hive.api.getDiscussionsByCashout(query, function(err, result) {
adcpm's avatar
adcpm committed
339
  console.log(err, result);
340
341
342
});
```
### Get Discussions By Payout
adcpm's avatar
adcpm committed
343
```
Mahdi Yari's avatar
Mahdi Yari committed
344
hive.api.getDiscussionsByPayout(query, function(err, result) {
adcpm's avatar
adcpm committed
345
  console.log(err, result);
346
347
348
});
```
### Get Discussions By Votes
adcpm's avatar
adcpm committed
349
```
Mahdi Yari's avatar
Mahdi Yari committed
350
hive.api.getDiscussionsByVotes(query, function(err, result) {
adcpm's avatar
adcpm committed
351
  console.log(err, result);
352
353
354
});
```
### Get Discussions By Children
adcpm's avatar
adcpm committed
355
```
Mahdi Yari's avatar
Mahdi Yari committed
356
hive.api.getDiscussionsByChildren(query, function(err, result) {
adcpm's avatar
adcpm committed
357
  console.log(err, result);
358
359
360
});
```
### Get Discussions By Hot
adcpm's avatar
adcpm committed
361
```
Mahdi Yari's avatar
Mahdi Yari committed
362
hive.api.getDiscussionsByHot(query, function(err, result) {
adcpm's avatar
adcpm committed
363
  console.log(err, result);
364
365
});
```
adcpm's avatar
adcpm committed
366
### Get Discussions By Feed
adcpm's avatar
adcpm committed
367
```
Mahdi Yari's avatar
Mahdi Yari committed
368
hive.api.getDiscussionsByFeed(query, function(err, result) {
adcpm's avatar
adcpm committed
369
370
371
372
373
  console.log(err, result);
});
```
### Get Discussions By Blog
```
Mahdi Yari's avatar
Mahdi Yari committed
374
hive.api.getDiscussionsByBlog(query, function(err, result) {
adcpm's avatar
adcpm committed
375
376
377
378
379
  console.log(err, result);
});
```
### Get Discussions By Comments
```
Mahdi Yari's avatar
Mahdi Yari committed
380
hive.api.getDiscussionsByComments(query, function(err, result) {
adcpm's avatar
adcpm committed
381
  console.log(err, result);
adcpm's avatar
adcpm committed
382
383
});
```
384

Mahdi Yari's avatar
Mahdi Yari committed
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
### Get Discussions By Promoted
Gets the recent posts ordered by how much was spent to promote them

```js
hive.api.getDiscussionsByPromoted(query, callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|query|object|an object containing different options for querying, like 'limit' and 'tag'|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
var query = { limit : 3, tag : "hive" };
hive.api.getDiscussionsByPromoted(query, function(err, data) {
	console.log(err, data);
});

// NOTE! The default limit is 0. Not setting a limit will get you an empty result.
```

Return Example:
```js
// the result is an array of big objects representing the comments

 [ { /* ommited for simplicity */ },
   { /* ommited for simplicity */ },
   { /* ommited for simplicity */ } ]
```

Mahdi Yari's avatar
Mahdi Yari committed
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
### Get Comment Discussions By Payout
Gets the recent comments (not posts) ordered by their pending payout.

```js
hive.api.getCommentDiscussionsByPayout(query, callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|query|object|an object containing different options for querying, like 'limit' and 'tag'|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
var query = { limit : 3, tag : "hive" };
hive.api.getCommentDiscussionsByPayout(query, function(err, data) {
	console.log(err, data);
});

// NOTE! The default limit is 0. Not setting a limit will get you an empty result.
```

Return Example:
```js
// the result is an array of big objects representing the comments

 [ { /* ommited for simplicity */ },
   { /* ommited for simplicity */ },
   { /* ommited for simplicity */ } ]
```

Mahdi Yari's avatar
Mahdi Yari committed
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
### Get Post Discussions By Payout
Gets the recent posts ordered by their pending payout.

```js
hive.api.getPostDiscussionsByPayout(query, callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|query|object|an object containing different options for querying, like 'limit' and 'tag'|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
var query = { limit : 3, tag : "collorchallenge" };
hive.api.getPostDiscussionsByPayout(query, function(err, data) {
	console.log(err, data);
});

// NOTE! The default limit is 0. Not setting a limit will get you an empty result.
```

Return Example:
```js
// the result is an array of big objects representing the comments

 [ { /* ommited for simplicity */ },
   { /* ommited for simplicity */ },
   { /* ommited for simplicity */ } ]
```

adcpm's avatar
adcpm committed
481
482
## Blocks and transactions

483
### Get Block Header
Mahdi Yari's avatar
Mahdi Yari committed
484
```js
Mahdi Yari's avatar
Mahdi Yari committed
485
hive.api.getBlockHeader(blockNum, function(err, result) {
adcpm's avatar
adcpm committed
486
  console.log(err, result);
487
488
489
});
```
### Get Block
Mahdi Yari's avatar
Mahdi Yari committed
490
```js
Mahdi Yari's avatar
Mahdi Yari committed
491
hive.api.getBlock(blockNum, function(err, result) {
adcpm's avatar
adcpm committed
492
  console.log(err, result);
493
});
Mahdi Yari's avatar
Mahdi Yari committed
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
```
### Get Ops In Block
Gets all operations in a given block

```js
hive.api.getOpsInBlock(blockNum, onlyVirtual, callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|blockNum|number|A positive number|
|onlyVirtual|bool|'false' to get all operations. 'true' to only get virtual operations|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
hive.api.getOpsInBlock(10000001, false, function(err, data) {
	console.log(err, data);
});
```

Return Example:
```js
[ { trx_id: '4b688c13940fd5b4bb11356286ef12061f71976c',
    block: 10000001,
    trx_in_block: 0,
    op_in_trx: 0,
    virtual_op: 0,
    timestamp: '2017-03-08T17:34:24',
    op: [ 'vote', [Object] ] },
  { trx_id: 'a450debc8332c3b27935b3307891dfc509669edc',
    block: 10000001,
    trx_in_block: 2,
    op_in_trx: 0,
    virtual_op: 0,
    timestamp: '2017-03-08T17:34:24',
    op: [ 'vote', [Object] ] } ]

533
534
```
### Get State
Mahdi Yari's avatar
Mahdi Yari committed
535
536
**Warning:** getState calls are getting deprecated.  

Mahdi Yari's avatar
Mahdi Yari committed
537
538
Gets a lot of information about the state of `path`

Mahdi Yari's avatar
Mahdi Yari committed
539
```js
Mahdi Yari's avatar
Mahdi Yari committed
540
hive.api.getState(path, function(err, result) {
adcpm's avatar
adcpm committed
541
  console.log(err, result);
542
543
});
```
Mahdi Yari's avatar
Mahdi Yari committed
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
|Parameter|Datatype|Description|
|---------|--------|-----------|
|path|string| like "/@username". This is the extension from the Hive URL. It can be used on users, posts, comments, comments-by-user, replies-to-user and so on|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
hive.api.getState("/@username", function(err, data) {
	console.log(err, data);
});

// Here are some valid calls:

hive.api.getState("/@username", function(err, data) { console.log(data); });

hive.api.getState("/@username/permlink-of-post", function(err, data) { console.log(data); });

hive.api.getState("/@username/comments", function(err, data) { console.log(data); });

hive.api.getState("/@username/recent-replies", function(err, data) { console.log(data); });

hive.api.getState("/trending", function(err, data) { console.log(data); });

hive.api.getState("/trending/collorchallenge", function(err, data) { console.log(data); });

// and others....
```

Return Example:
```js
// The result is huge, and can have many variations depending on what you are getting the state of. It can't be documented briefly. Here is some basic information:
{	accounts: {username: {...}}
	content: {
		username/permlink1: {...},
		username/permlink2: {...}, 
		username/permlink3: {...} …}
	current_route:"/@username"
	discussion_idx: {...}
	error:""
	feed_price: {base: "3.889 HBD", quote: "1.000 HIVE"}
	pow_queue: []
	props: {...}
	tag_idx: { trending: [...] }
	tags:{...}
	witness_schedule: {...}
	witnesses: {...}	}
```

Mahdi Yari's avatar
Mahdi Yari committed
593
### Get State With Options
Mahdi Yari's avatar
Mahdi Yari committed
594
**Warning:** getState calls are getting deprecated.
Mahdi Yari's avatar
Mahdi Yari committed
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613

```js
hive.api.getStateWith(options, callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|options|object|like { path : "/@username"} where the path is an extension from a Hive URL. It can be used on users, posts, comments, comments-by-user, replies-to-user and so on|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
hive.api.getStateWith({ path : "/@username" }, function(err, data) {
	console.log(err, data);
});
```
See `hive.api.getState` for more examples...

614
### Get Trending Categories
Mahdi Yari's avatar
Mahdi Yari committed
615
```js
Mahdi Yari's avatar
Mahdi Yari committed
616
hive.api.getTrendingCategories(after, limit, function(err, result) {
adcpm's avatar
adcpm committed
617
  console.log(err, result);
618
619
620
});
```
### Get Best Categories
Mahdi Yari's avatar
Mahdi Yari committed
621
```js
Mahdi Yari's avatar
Mahdi Yari committed
622
hive.api.getBestCategories(after, limit, function(err, result) {
adcpm's avatar
adcpm committed
623
  console.log(err, result);
624
625
626
});
```
### Get Active Categories
Mahdi Yari's avatar
Mahdi Yari committed
627
```js
Mahdi Yari's avatar
Mahdi Yari committed
628
hive.api.getActiveCategories(after, limit, function(err, result) {
adcpm's avatar
adcpm committed
629
  console.log(err, result);
630
631
632
});
```
### Get Recent Categories
Mahdi Yari's avatar
Mahdi Yari committed
633
```js
Mahdi Yari's avatar
Mahdi Yari committed
634
hive.api.getRecentCategories(after, limit, function(err, result) {
adcpm's avatar
adcpm committed
635
  console.log(err, result);
636
637
638
639
});
```

## Globals
adcpm's avatar
adcpm committed
640

641
### Get Config
Mahdi Yari's avatar
Mahdi Yari committed
642
```js
Mahdi Yari's avatar
Mahdi Yari committed
643
hive.api.getConfig(function(err, result) {
adcpm's avatar
adcpm committed
644
  console.log(err, result);
645
646
647
});
```
### Get Dynamic Global Properties
Mahdi Yari's avatar
Mahdi Yari committed
648
```js
Mahdi Yari's avatar
Mahdi Yari committed
649
hive.api.getDynamicGlobalProperties(function(err, result) {
adcpm's avatar
adcpm committed
650
  console.log(err, result);
651
652
653
});
```
### Get Chain Properties
Mahdi Yari's avatar
Mahdi Yari committed
654
```js
Mahdi Yari's avatar
Mahdi Yari committed
655
hive.api.getChainProperties(function(err, result) {
adcpm's avatar
adcpm committed
656
  console.log(err, result);
657
658
});
```
Mahdi Yari's avatar
Mahdi Yari committed
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
### Get Feed Entries
Gets the posts in the feed of a user.
The feed displays posts of followed users, as well as what they reblogged.

```js
hive.api.getFeedEntries(account, entryId, limit, callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|account|string|a hive username|
|entryId|number|the post id from which to start counting. Write '0' to start from newest post|
|limit|number|a positive number|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
hive.api.getFeedEntries("username", 0, 2, function(err, data) {
	console.log(err, data);
});
```

Return Example:
```js
[
  {
    author: 'otherusername',
    permlink: 'permlink',
    reblog_by: ['mahdiyari'], //full when post is in feed because it's reblogged
    reblog_on: '2018-02-11T18:42:54',
    entry_id: 10260
  },
  {
    author: 'otherusername',
    permlink: 'permlink',
    reblog_by: [], // false when post is in feed because user follows it's author
    reblog_on: '2018-02-11T18:39:24',
    entry_id: 10259
  }
]
```
701
### Get Feed History
Mahdi Yari's avatar
Mahdi Yari committed
702
```js
Mahdi Yari's avatar
Mahdi Yari committed
703
hive.api.getFeedHistory(function(err, result) {
adcpm's avatar
adcpm committed
704
  console.log(err, result);
705
706
707
});
```
### Get Current Median History Price
Mahdi Yari's avatar
Mahdi Yari committed
708
```js
Mahdi Yari's avatar
Mahdi Yari committed
709
hive.api.getCurrentMedianHistoryPrice(function(err, result) {
adcpm's avatar
adcpm committed
710
  console.log(err, result);
711
712
});
```
Mahdi Yari's avatar
Mahdi Yari committed
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
### Get Ticker
Gets the lates summorized data from the hive market.

```js
hive.api.getTicker(callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
hive.api.getTicker(function(err, data) {
	console.log(err, data);
});
```

Return Example:
```js
{ latest: '0.89732142857142860',
  lowest_ask: '0.89684014869888484',
  highest_bid: '0.89600000000000002',
  percent_change: '-14.56712923228768730',
  hive_volume: '7397.697 HIVE',
  hbd_volume: '6662.316 HBD' }
```
Mahdi Yari's avatar
Mahdi Yari committed
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
### Get Trade History
Gets the trade history for a given period between a `start` date and an `end` date

```js
hive.api.getTradeHistory(start, end, limit, callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|start|string|Datetime string in the format "2018-01-01T00:00:00"|
|end|string|Datetime string in the format "2018-01-01T00:00:00"|
|limit|number|a positive number|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
var start = "2018-01-01T00:00:00";
var end = "2018-01-02T00:00:00";

hive.api.getTradeHistory(start, end, 5, function(err, data) {
	console.log(err, data);
});
```

Return Example:
```js
 [ { date: '2018-01-01T00:00:09',
    current_pays: '10.192 HBD',
    open_pays: '25.650 HIVE' },
  { date: '2018-01-01T00:00:09',
    current_pays: '2.000 HBD',
    open_pays: '5.033 HIVE' },
  { date: '2018-01-01T00:00:12',
    current_pays: '13.560 HBD',
    open_pays: '34.128 HIVE' },
  { date: '2018-01-01T00:00:12',
    current_pays: '3.057 HBD',
    open_pays: '7.690 HIVE' },
  { date: '2018-01-01T00:00:12',
    current_pays: '6.908 HBD',
    open_pays: '17.375 HIVE' } ] 
```
Mahdi Yari's avatar
Mahdi Yari committed
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
### Get Version
Gets the version of the Hive blockchain you are connected to.

```js
hive.api.getVersion(callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
hive.api.getVersion(function(err, data) {
	console.log(err, data);
});
```

Return Example:
```js
{
  blockchain_version: '1.24.4',
  chain_id: 'beeab0de00000000000000000000000000000000000000000000000000000000',
  fc_revision: 'b91e5d490e3647cc816748a5565452b663c6aa73',
  hive_revision: 'b91e5d490e3647cc816748a5565452b663c6aa73'
}
```
Mahdi Yari's avatar
Mahdi Yari committed
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
### Get Volume
Gets the Hive and Hive Dollar volumes

```js
hive.api.getVolume(callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
hive.api.getVolume(function(err, data) {
	console.log(err, data);
});
```

Return Example:
```js
{ hive_volume: '8101.888 HIVE',
	hbd_volume: '7287.268 HBD' }
```
836
### Get Hardfork Version
Mahdi Yari's avatar
Mahdi Yari committed
837
Gets the current hardfork version of the Hive blockchain.
Mahdi Yari's avatar
Mahdi Yari committed
838
```js
Mahdi Yari's avatar
Mahdi Yari committed
839
hive.api.getHardforkVersion(function(err, result) {
adcpm's avatar
adcpm committed
840
  console.log(err, result);
841
842
});
```
Mahdi Yari's avatar
Mahdi Yari committed
843
844
845
846
847
848
849
Return Example:
```js
'1.24.0'
```
This returns a string and not JSON.

See also: [getNextScheduledHardfork](#get-next-scheduled-hardfork), [getConfig](#get-config)
850
### Get Next Scheduled Hardfork
Mahdi Yari's avatar
Mahdi Yari committed
851
```js
Mahdi Yari's avatar
Mahdi Yari committed
852
hive.api.getNextScheduledHardfork(function(err, result) {
adcpm's avatar
adcpm committed
853
  console.log(err, result);
854
855
});
```
adcpm's avatar
adcpm committed
856
### Get Reward Fund
Mahdi Yari's avatar
Mahdi Yari committed
857
```js
Mahdi Yari's avatar
Mahdi Yari committed
858
hive.api.getRewardFund(name, function(err, result) {
adcpm's avatar
adcpm committed
859
860
861
  console.log(err, result);
});
```
Mahdi Yari's avatar
Mahdi Yari committed
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
### Claim Reward Balance
Claims pending rewards, be they HIVE, HBD or VESTS.

```js
hive.broadcast.claimRewardBalance(wif, account, reward_hive, reward_hbd, reward_vests, callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|wif|string|Use hive.auth.toWif(user, pass, type)|
|account|string|a hive username|
|reward_hive|string|balance like "0.000 HIVE"|
|reward_hbd|string|balance like "0.000 HBD"|
|reward_vests|string|balance like "0.000006 VESTS"|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
hive.broadcast.claimRewardBalance("5Hupd....pp7vGY", "username", "0.000 HIVE", "0.000 HBD", "0.000006 VESTS", function(err, data) {
	console.log(err, data);
});
```

Return Example:
```js
{ id: '052f.......c6c2f',
  block_num: 19756287,
  trx_num: 40,
  expired: false,
  ref_block_num: 29928,
  ref_block_prefix: 808836877,
  expiration: '2018-02-10T20:12:15',
  operations: [ [ 'claim_reward_balance', [Object] ] ],
  extensions: [],
  signatures: [ '205......614e' ] }
```
Mahdi Yari's avatar
Mahdi Yari committed
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
### Claim Reward Balance With Options
Claims pending rewards, be they HIVE, HBD or VESTS.

```js
hive.broadcast.claimRewardBalanceWith(wif, options, callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|wif|string|Use < hive.auth.toWif(user, pass, type) >|
|options|object|an object containing the calim parameters. Look at the example below.|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
var options = {
    account:"username",
    reward_hbd:"0.000 HBD",
    reward_hive:"0.000 HIVE",
    reward_vests:"0.000006 VESTS"
}
hive.broadcast.claimRewardBalanceWith("5Hupd....pp7vGY", options, function(err, data) {
	console.log(err, data);
});
```

Return Example:
```js
 { id: '4b7b........034c7',
  block_num: 19756322,
  trx_num: 3,
  expired: false,
  ref_block_num: 29965,
  ref_block_prefix: 4245658614,
  expiration: '2018-02-10T20:14:00',
  operations: [ [ 'claim_reward_balance', [Object] ] ],
  extensions: [],
  signatures: [ '1f61a..........4f3d7' ] }
```
adcpm's avatar
adcpm committed
939
### Get Vesting Delegations
Mahdi Yari's avatar
Mahdi Yari committed
940
Returns a list of delegations made from one `account`. Denominated in VESTS.
Mahdi Yari's avatar
Mahdi Yari committed
941
```js
Mahdi Yari's avatar
Mahdi Yari committed
942
hive.api.getVestingDelegations(account, from, limit, function(err, result) {
adcpm's avatar
adcpm committed
943
944
945
  console.log(err, result);
});
```
Mahdi Yari's avatar
Mahdi Yari committed
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
|Parameter|Description|Datatype|Notes|
|---|---|---|---|
|account|Account who is making the delegations|String||
|from|The name of the last account to begin from|String|Use the empty string `''` to start the list. Subsequent calls can use the last delegatee's account name|
|limit|The maximum number of delegation records to return|Integer||
|function()|Your callback|function|Tip: use `console.log(err, result)` to see the result|


Call Example:
```js
hive.api.getVestingDelegations('mahdiyari', '', 2, function(err, result) {
  console.log(err, result);
});
```

Return Example:
```js
[
  {
    delegatee: 'dblog-io',
    delegator: 'mahdiyari',
    id: 980695,
    min_delegation_time: '2018-08-03T20:33:21',
    vesting_shares: '29429.940343 VESTS'
  },
  {
    delegatee: 'lokio',
    delegator: 'mahdiyari',
    id: 1359266,
    min_delegation_time: '2020-10-21T12:15:18',
    vesting_shares: '28832.135025 VESTS'
  }
]
```
Mahdi Yari's avatar
Mahdi Yari committed
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
Using the Result:
```js
// Extract delegatee names from the result into an array of account name strings
var f = result.map(function(item) { return item.delegatee; });
console.log(f);

// Get the last tag for subsequent calls to `getVestingDelegations`
//   or use: f[f.length - 1]   if you used the extraction code above.
var lastKnownDelegatee = result[result.length - 1].delegatee;

// Use the last known delegatee to get the next group of delegatees
hive.api.TrendingTags('mahdiyari', lastKnownDelegatee, 2, function(err, result) {
  console.log(err, result);
});
```

See also: [accountCreateWithDelegation](#account-create-with-delegation), [delegateVestingShares](#delegate-vesting-shares)
997
998

## Keys
adcpm's avatar
adcpm committed
999

1000
### Get Key References
Mahdi Yari's avatar
Mahdi Yari committed
1001
```js
Mahdi Yari's avatar
Mahdi Yari committed
1002
hive.api.getKeyReferences(key, function(err, result) {
adcpm's avatar
adcpm committed
1003
  console.log(err, result);
1004
1005
1006
1007
});
```

## Accounts
adcpm's avatar
adcpm committed
1008

1009
### Get Accounts
Mahdi Yari's avatar
Mahdi Yari committed
1010
```js
Mahdi Yari's avatar
Mahdi Yari committed
1011
hive.api.getAccounts(names, function(err, result) {
adcpm's avatar
adcpm committed
1012
  console.log(err, result);
1013
1014
1015
});
```
### Get Account References
Mahdi Yari's avatar
Mahdi Yari committed
1016
```js
Mahdi Yari's avatar
Mahdi Yari committed
1017
hive.api.getAccountReferences(accountId, function(err, result) {
adcpm's avatar
adcpm committed
1018
  console.log(err, result);
1019
1020
1021
});
```
### Lookup Account Names
Mahdi Yari's avatar
Mahdi Yari committed
1022
```js
Mahdi Yari's avatar
Mahdi Yari committed
1023
hive.api.lookupAccountNames(accountNames, function(err, result) {
adcpm's avatar
adcpm committed
1024
  console.log(err, result);
1025
1026
1027
});
```
### Lookup Accounts
Mahdi Yari's avatar
Mahdi Yari committed
1028
```js
Mahdi Yari's avatar
Mahdi Yari committed
1029
hive.api.lookupAccounts(lowerBoundName, limit, function(err, result) {
adcpm's avatar
adcpm committed
1030
  console.log(err, result);
1031
1032
1033
});
```
### Get Account Count
Mahdi Yari's avatar
Mahdi Yari committed
1034
```js
Mahdi Yari's avatar
Mahdi Yari committed
1035
hive.api.getAccountCount(function(err, result) {
adcpm's avatar
adcpm committed
1036
  console.log(err, result);
1037
1038
1039
});
```
### Get Conversion Requests
Mahdi Yari's avatar
Mahdi Yari committed
1040
```js
Mahdi Yari's avatar
Mahdi Yari committed
1041
hive.api.getConversionRequests(accountName, function(err, result) {
adcpm's avatar
adcpm committed
1042
  console.log(err, result);
1043
1044
1045
});
```
### Get Account History
Mahdi Yari's avatar
Mahdi Yari committed
1046
```js
1047
hive.api.getAccountHistory(account, from, limit, operation_filter_low, operation_filter_high, function(err, result) {
adcpm's avatar
adcpm committed
1048
  console.log(err, result);
1049
});
Mahdi Yari's avatar
Mahdi Yari committed
1050
1051
1052
```  
Example:  

Mahdi Yari's avatar
Mahdi Yari committed
1053
```js
Mahdi Yari's avatar
Mahdi Yari committed
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
const { ChainTypes, makeBitMaskFilter } = require('@hiveio/hive-js/lib/auth/serializer')
const op = ChainTypes.operations
const walletOperationsBitmask = makeBitMaskFilter([
  op.transfer,
  op.transfer_to_vesting,
  op.withdraw_vesting,
  op.interest,
  op.liquidity_reward,
  op.transfer_to_savings,
  op.transfer_from_savings,
  op.escrow_transfer,
  op.cancel_transfer_from_savings,
  op.escrow_approve,
  op.escrow_dispute,
  op.escrow_release,
  op.fill_convert_request,
  op.fill_order,
  op.claim_reward_balance
])
hive.api.getAccountHistory(account, from, limit, ...walletOperationsBitmask, function(err, result) {
  console.log(err, result)
})
```  


1079
### Get Owner History
Mahdi Yari's avatar
Mahdi Yari committed
1080
```js
Mahdi Yari's avatar
Mahdi Yari committed
1081
hive.api.getOwnerHistory(account, function(err, result) {
adcpm's avatar
adcpm committed
1082
  console.log(err, result);
1083
1084
1085
});
```
### Get Recovery Request
Mahdi Yari's avatar
Mahdi Yari committed
1086
```js
Mahdi Yari's avatar
Mahdi Yari committed
1087
hive.api.getRecoveryRequest(account, function(err, result) {
adcpm's avatar
adcpm committed
1088
  console.log(err, result);
1089
1090
1091
});
```

Mahdi Yari's avatar
Mahdi Yari committed
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
### Get Account Reputations
Gets the reputation points of `limit` accounts with names most similar to `lowerBoundName`.

```js
hive.api.getAccountReputations(lowerBoundName, limit, callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|lowerBoundName|string|a hive username query|
|limit|number|a positive number|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
hive.api.getAccountReputations("username", 2, function(err, data) {
	console.log(err, data);
});
```

Return Example:
```js
 [ { account: 'username', reputation: '26727073581' },
   { account: 'username-taken', reputation: 0 } ]
```

1119
## Market
adcpm's avatar
adcpm committed
1120

1121
### Get Order Book
Mahdi Yari's avatar
Mahdi Yari committed
1122
```js
Mahdi Yari's avatar
Mahdi Yari committed
1123
hive.api.getOrderBook(limit, function(err, result) {
adcpm's avatar
adcpm committed
1124
  console.log(err, result);
1125
1126
});
```
Mahdi Yari's avatar
Mahdi Yari committed
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
### Get Market Order Book
Takes the top-most `limit` entries in the market order book for both buy and sell orders.

```js
hive.api.getMarketOrderBook(limit, callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|limit|number|a positive number|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
hive.api.getMarketOrderBook(2, function(err, data) {
	console.log(err, data);
});
```

Return Example:
```js
{
  asks: [
    {
      created: '2020-11-03T15:24:54',
      hbd: 227,
      hive: 1915,
      order_price: [Object],
      real_price: '0.11853785900783290'
    },
    {
      created: '2020-11-03T15:20:51',
      hbd: 1244,
      hive: 10463,
      order_price: [Object],
      real_price: '0.11889515435343592'
    }
  ],
  bids: [
    {
      created: '2020-11-03T15:23:03',
      hbd: 2000,
      hive: 16948,
      order_price: [Object],
      real_price: '0.11800802454566911'
    },
    {
      created: '2020-11-03T15:21:51',
      hbd: 44673,
      hive: 378585,
      order_price: [Object],
      real_price: '0.11799992075755775'
    }
  ]
}
```
Mahdi Yari's avatar
Mahdi Yari committed
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
### Get Market Order Book With Options
Takes the top-most `limit` entries in the market order book for both buy and sell orders.

```js
hive.api.getMarketOrderBookWith(options, callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|options|object|like { limit:number }|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
hive.api.getMarketOrderBookWith({ limit: 1 }, function(err, data) {
	console.log(err, data);
});
```

Return Example:
```js
{
  asks: [
    {
      created: '2020-11-03T15:24:54',
      hbd: 227,
      hive: 1915,
      order_price: [Object],
      real_price: '0.11853785900783290'
    }
  ],
  bids: [
    {
      created: '2020-11-03T15:29:30',
      hbd: 5990,
      hive: 50533,
      order_price: [Object],
      real_price: '0.11853640195515802'
    }
  ]
}
```
1227
### Get Open Orders
Mahdi Yari's avatar
Mahdi Yari committed
1228
```js
Mahdi Yari's avatar
Mahdi Yari committed
1229
hive.api.getOpenOrders(owner, function(err, result) {
adcpm's avatar
adcpm committed
1230
  console.log(err, result);
1231
1232
1233
});
```
### Get Liquidity Queue
Mahdi Yari's avatar
Mahdi Yari committed
1234
```js
Mahdi Yari's avatar
Mahdi Yari committed
1235
hive.api.getLiquidityQueue(startAccount, limit, function(err, result) {
adcpm's avatar
adcpm committed
1236
  console.log(err, result);
1237
1238
});
```
Mahdi Yari's avatar
Mahdi Yari committed
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
### Get Market History Buckets

```js
hive.api.getMarketHistoryBuckets(callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
hive.api.getMarketHistoryBuckets(function(err, data) {
	console.log(err, data);
});
```

Return Example:
```js
 [ 15, 60, 300, 3600, 86400 ]
```
1261

adcpm's avatar
adcpm committed
1262
1263
## Authority / validation

1264
### Get Transaction Hex
Mahdi Yari's avatar
Mahdi Yari committed
1265
```js
Mahdi Yari's avatar
Mahdi Yari committed
1266
hive.api.getTransactionHex(trx, function(err, result) {
adcpm's avatar
adcpm committed
1267
  console.log(err, result);
1268
1269
1270
});
```
### Get Transaction
Mahdi Yari's avatar
Mahdi Yari committed
1271
```js
Mahdi Yari's avatar
Mahdi Yari committed
1272
hive.api.getTransaction(trxId, function(err, result) {
adcpm's avatar
adcpm committed
1273
  console.log(err, result);
1274
1275
1276
});
```
### Get Required Signatures
Mahdi Yari's avatar
Mahdi Yari committed
1277
```js
Mahdi Yari's avatar
Mahdi Yari committed
1278
hive.api.getRequiredSignatures(trx, availableKeys, function(err, result) {
adcpm's avatar
adcpm committed
1279
  console.log(err, result);
1280
1281
1282
});
```
### Get Potential Signatures
Mahdi Yari's avatar
Mahdi Yari committed
1283
```js
Mahdi Yari's avatar
Mahdi Yari committed
1284
hive.api.getPotentialSignatures(trx, function(err, result) {
adcpm's avatar
adcpm committed
1285
  console.log(err, result);
1286
1287
1288
});
```
### Verify Authority
Mahdi Yari's avatar
Mahdi Yari committed
1289
```js
Mahdi Yari's avatar
Mahdi Yari committed
1290
hive.api.verifyAuthority(trx, function(err, result) {
adcpm's avatar
adcpm committed
1291
  console.log(err, result);
1292
1293
1294
});
```
### Verify Account Authority
Mahdi Yari's avatar
Mahdi Yari committed
1295
```js
Mahdi Yari's avatar
Mahdi Yari committed
1296
hive.api.verifyAccountAuthority(nameOrId, signers, function(err, result) {
adcpm's avatar
adcpm committed
1297
  console.log(err, result);
1298
1299
1300
1301
});
```

## Votes
adcpm's avatar
adcpm committed
1302

1303
### Get Active Votes
Mahdi Yari's avatar
Mahdi Yari committed
1304
```js
Mahdi Yari's avatar
Mahdi Yari committed
1305
hive.api.getActiveVotes(author, permlink, function(err, result) {
adcpm's avatar
adcpm committed
1306
  console.log(err, result);
1307
1308
1309
});
```
### Get Account Votes
Mahdi Yari's avatar
Mahdi Yari committed
1310
```js
Mahdi Yari's avatar
Mahdi Yari committed
1311
hive.api.getAccountVotes(voter, function(err, result) {
adcpm's avatar
adcpm committed
1312
  console.log(err, result);
1313
1314
1315
1316
});
```

## Content
adcpm's avatar
adcpm committed
1317
1318


1319
### Get Content
Mahdi Yari's avatar
Mahdi Yari committed
1320
```js
Mahdi Yari's avatar
Mahdi Yari committed
1321
hive.api.getContent(author, permlink, function(err, result) {
adcpm's avatar
adcpm committed
1322
  console.log(err, result);
1323
1324
1325
});
```
### Get Content Replies
Mahdi Yari's avatar
Mahdi Yari committed
1326
```js
Mahdi Yari's avatar
Mahdi Yari committed
1327
hive.api.getContentReplies(author, permlink, function(err, result) {
adcpm's avatar
adcpm committed
1328
  console.log(err, result);
1329
1330
});
```
adcpm's avatar
adcpm committed
1331
### Get Discussions By Author Before Date
Mahdi Yari's avatar
Mahdi Yari committed
1332
```js
Mahdi Yari's avatar
Mahdi Yari committed
1333
hive.api.getDiscussionsByAuthorBeforeDate(author, startPermlink, beforeDate, limit, function(err, result) {
adcpm's avatar
adcpm committed
1334
  console.log(err, result);
1335
1336
});
```
Mahdi Yari's avatar
Mahdi Yari committed
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
### Get Reblogged By
Gives a list of the users that reblogged a given post

```js
hive.api.getRebloggedBy(author, permlink, callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|author|string|a hive username|
|permlink|string|a permalink of comment or post|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
hive.api.getRebloggedBy("author", "example-permlink", function(err, data) {
	console.log(err, data);
});
```

Return Example:
```js
 [ 'author',
  'user1',
  'user2',
  'user3',
  'user4' ]
```
1366
### Get Replies By Last Update
Mahdi Yari's avatar
Mahdi Yari committed
1367
```js
Mahdi Yari's avatar
Mahdi Yari committed
1368
hive.api.getRepliesByLastUpdate(startAuthor, startPermlink, limit, function(err, result) {
adcpm's avatar
adcpm committed
1369
  console.log(err, result);
1370
1371
1372
1373
});
```

## Witnesses
adcpm's avatar
adcpm committed
1374
1375


1376
### Get Witnesses
Mahdi Yari's avatar
Mahdi Yari committed
1377
```js
Mahdi Yari's avatar
Mahdi Yari committed
1378
hive.api.getWitnesses(witnessIds, function(err, result) {
adcpm's avatar
adcpm committed
1379
  console.log(err, result);
1380
1381
1382
});
```
### Get Witness By Account
Mahdi Yari's avatar
Mahdi Yari committed
1383
```js
Mahdi Yari's avatar
Mahdi Yari committed
1384
hive.api.getWitnessByAccount(accountName, function(err, result) {
adcpm's avatar
adcpm committed
1385
  console.log(err, result);
1386
1387
1388
});
```
### Get Witnesses By Vote
Mahdi Yari's avatar
Mahdi Yari committed
1389
```js
Mahdi Yari's avatar
Mahdi Yari committed
1390
hive.api.getWitnessesByVote(from, limit, function(err, result) {
adcpm's avatar
adcpm committed
1391
  console.log(err, result);
1392
1393
1394
});
```
### Lookup Witness Accounts
Mahdi Yari's avatar
Mahdi Yari committed
1395
```js
Mahdi Yari's avatar
Mahdi Yari committed
1396
hive.api.lookupWitnessAccounts(lowerBoundName, limit, function(err, result) {
adcpm's avatar
adcpm committed
1397
  console.log(err, result);
1398
1399
});
```
Mahdi Yari's avatar
Mahdi Yari committed
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
### Get Witness Schedule
Gets some general information about the witnesses.

```js
hive.api.getWitnessSchedule(callback);
```

|Parameter|Datatype|Description|
|---------|--------|-----------|
|callback|function|function(err, data) {/*code*/}|


Call Example:
```js
hive.api.getWitnessSchedule(function(err, data) {
  console.log(err,data);
})
```

Return Example:
```js
{
  id: 0,
  current_virtual_time: '576908375209337450843859945',
  next_shuffle_block_num: 48367095,
  current_shuffled_witnesses: [
    'cervantes',   'themarkymark',
    'pharesim',    'stoodkev',
    'ausbitbank',  'followbtcnews',
    'anyx',        'gtg',
    'steempeak',   'therealwolf',
    'drakos',      'good-karma',
    'blocktrades', 'roelandp',
    'emrebeyler',  'ocd-witness',
    'arcange',     'someguy123',
    'steempress',  'yabapmatt',
    'abit'
  ],
  num_scheduled_witnesses: 21,
  elected_weight: 1,
  timeshare_weight: 5,
  miner_weight: 1,
  witness_pay_normalization_factor: 25,
  median_props: {
    account_creation_fee: '3.000 HIVE',
    maximum_block_size: 65536,
    hbd_interest_rate: 0,
    account_subsidy_budget: 797,
    account_subsidy_decay: 347321
  },
  majority_version: '1.24.2',
  max_voted_witnesses: 20,
  max_miner_witnesses: 0,
  max_runner_witnesses: 1,
  hardfork_required_witnesses: 17,
  account_subsidy_rd: {
    resource_unit: 10000,
    budget_per_time_unit: 797,
    pool_eq: 157691079,
    max_pool_size: 157691079,
    decay_params: {
      decay_per_time_unit: 347321,
      decay_per_time_unit_denom_shift: 36
    },
    min_decay: 0
  },
  account_subsidy_witness_rd: {
    resource_unit: 10000,
    budget_per_time_unit: 996,
    pool_eq: 9384019,
    max_pool_size: 9384019,
    decay_params: {
      decay_per_time_unit: 7293741,
      decay_per_time_unit_denom_shift: 36
    },
    min_decay: 216
  },
  min_witness_account_subsidy_decay: 0
}
```
1480
### Get Witness Count
Mahdi Yari's avatar
Mahdi Yari committed
1481
```js
Mahdi Yari's avatar
Mahdi Yari committed
1482
hive.api.getWitnessCount(function(err, result) {
adcpm's avatar
adcpm committed
1483
  console.log(err, result);
1484
1485
1486
});
```
### Get Active Witnesses
Mahdi Yari's avatar
Mahdi Yari committed
1487
```js
Mahdi Yari's avatar
Mahdi Yari committed
1488
hive.api.getActiveWitnesses(function(err, result) {
adcpm's avatar
adcpm committed
1489
  console.log(err, result);
1490
1491
1492
});
```

adcpm's avatar
adcpm committed
1493
1494
1495
## Login API

### Login
Fabien's avatar
Fabien committed
1496
1497
1498

/!\ It's **not safe** to use this method with your username and password. This method always return `true` and is only used in intern with empty values to enable broadcast.

Mahdi Yari's avatar
Mahdi Yari committed
1499
```js
Mahdi Yari's avatar
Mahdi Yari committed
1500
hive.api.login('', '', function(err, result) {
adcpm's avatar
adcpm committed
1501
1502
1503
  console.log(err, result);
});
```
Fabien's avatar
Fabien committed
1504

adcpm's avatar
adcpm committed
1505
### Get Api By Name
Mahdi Yari's avatar
Mahdi Yari committed
1506
```js
Mahdi Yari's avatar
Mahdi Yari committed
1507
hive.api.getApiByName(apiName, function(err, result) {
adcpm's avatar
adcpm committed
1508
  console.log(err, result);
adcpm's avatar
adcpm committed
1509
1510
1511
});
```

adcpm's avatar
adcpm committed
1512
## Follow API
Mahdi Yari's avatar
Mahdi Yari committed
1513
The follower API queries information about follow relationships between accounts. The API is read-only and does not create changes on the blockchain.
adcpm's avatar
adcpm committed
1514

adcpm's avatar
adcpm committed
1515
### Get Followers
Mahdi Yari's avatar
Mahdi Yari committed
1516
Returns an alphabetical ordered array of the accounts that are following a particular account.
Mahdi Yari's avatar
Mahdi Yari committed
1517
```js
Mahdi Yari's avatar
Mahdi Yari committed
1518
hive.api.getFollowers(following, startFollower, followType, limit, function(err, result) {
adcpm's avatar
adcpm committed
1519
  console.log(err, result);
1520
1521
});
```
Mahdi Yari's avatar
Mahdi Yari committed
1522
1523
1524
1525
|Parameter|Description|Datatype|Notes|
|---|---|---|---|
|following|The followers of which account|String|No leading @ symbol|
|startFollower|Start the list from which follower?|String|No leading @symbol. Use the empty string `''` to start the list. Subsequent calls can use the name of the last follower|
RK's avatar
RK committed
1526
1527
|followType|Follow or mute|String|Set to 'blog' for followers or 'ignore' for mutes|
|limit|The maximum number of followers to return|Integer|1000 is maximum|
Mahdi Yari's avatar
Mahdi Yari committed
1528
1529
1530
1531
|function()|Your callback|function|Tip: use `console.log(err, result)` to see the result|

Call Example:
```js
RK's avatar
RK committed
1532
hive.api.getFollowers('username', '', 'blog', 2, function(err, result) {
Mahdi Yari's avatar
Mahdi Yari committed
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
  console.log(err, result);
});
```

Return Example:
```js
[ { follower: 'user1', following: 'username', what: [ 'blog' ] },
  { follower: 'user2', following: 'username', what: [ 'blog' ] } ]
```

Using the Result:
```js
// Extract followers from the result into an array of account name strings
var f = result.map(function(item) { return item.follower; });
console.log(f);

// Get the last follower for subsequent calls to getFollowers
//   or use: f[f.length - 1]   if you used the extraction code above.
var lastKnownFollower = result[result.length - 1].follower;

// Use the last known follower to get the next group of followers
hive.api.getFollowers('username', lastKnownFollower, 'blog', 2, function(err, result) {
  console.log(err, result);
});
```
See also: [getFollowing](#get-following), [getFollowCount](#get-follow-count)

adcpm's avatar
adcpm committed
1560
### Get Following
Mahdi Yari's avatar
Mahdi Yari committed
1561
1562
Returns an alphabetical ordered Array of the accounts that are followed by a particular account.
```js
Mahdi Yari's avatar
Mahdi Yari committed
1563
hive.api.getFollowing(follower, startFollowing, followType, limit, function(err, result) {
adcpm's avatar
adcpm committed
1564
1565
1566
  console.log(err, result);
});
```
Mahdi Yari's avatar
Mahdi Yari committed
1567
1568
1569
1570
1571

|Parameter|Description|Datatype|Notes|
|---|---|---|---|
|follower|The account to get the following for|String|No leading @ symbol|
|startFollowing|Start the list at which followed account?|String|No leading @symbol. Use the empty string `''` to start the list|
RK's avatar
RK committed
1572
1573
|followType|Follow or mute|String|Set to 'blog' for following or 'ignore' for muted|
|limit|The maximum number of items to return|Integer|1000 is maximum|
Mahdi Yari's avatar
Mahdi Yari committed
1574
1575
1576
1577
1578
1579
1580
|function()|Your callback|function|Tip: use `console.log(err, result)` to see the result|

Call Example:
```js
hvie.api.getFollowing('username', '', 'blog', 2, function(err, result) {
  console.log(err, result);
});
adcpm's avatar
adcpm committed
1581
```
Mahdi Yari's avatar
Mahdi Yari committed
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599

Return Example:
```js
[ { follower: 'username', following: 'user1', what: [ 'blog' ] },
  { follower: 'username', following: 'user2', what: [ 'blog' ] } ]
```

Using the Result:
```js
// Extract followed accounts from the result into an array of account name strings
var f = result.map(function(item) { return item.following; });
```
See the usage examples for [getFollowers](#get-followers) because the behaviour is very similar.

See also: [getFollowers](#get-followers), [getFollowCount](#get-follow-count)

### Get Follow Count
```js
Mahdi Yari's avatar
Mahdi Yari committed
1600
hive.api.getFollowCount(account, function(err, result) {
adcpm's avatar
adcpm committed
1601
  console.log(err, result);
1602
1603
});
```
adcpm's avatar
adcpm committed
1604

Mahdi Yari's avatar
Mahdi Yari committed
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
|Parameter|Description|Datatype|Notes|
|---|---|---|---|
|account|The name for get the follow ccount for|String|No leading @ symbol|
|function()|Your callback|function|Tip: use `console.log(err, result)` to see the result|


Call Example:
```js
hive.api.getFollowCount('username', function(err, result) {
  console.log(err, result);
});
```

Return Example:
```js
{ account: 'username', follower_count: 16790, following_count: 913 }
```

See also: [getFollowers](#get-followers), [getFollowing](#get-following)

adcpm's avatar