Hive-js & Hive-tx migration to Hive - Breaking changes for browsers!

in HiveDevs4 years ago


hivejshivetx.jpg

Hive-js

Hive-js is the official javascript library for Hive. All the apps previously using Steem-js should use Hive-js instead.

Installation:

npm install @hiveio/hive-js --save

Browser usage:

<script src="https://cdn.jsdelivr.net/npm/@hiveio/hive-js/dist/hive.min.js"></script>

New config option:

hive.config.set('alternative_api_endpoints', ['https://api.hive.blog', 'https://anyx.io']);

Breaking changes (Only on browsers):
The only breaking change is the variable name on the browsers. You must use hive instead of steem in the browsers to access Hive-js library.

Example usage:

hive.api.getAccounts(['mahdiyari', 'hiveio'], function(err, result) {
    console.log(err, result);
});

Deprecated method:
hive.formatter.vestToSteem() is deprecated and will be removed in the future releases. Use hive.formatter.vestToHive() instead.

var hivePower = hive.formatter.vestToHive(vestingShares, totalVestingShares, totalVestingFundHive);

Source code and full documentation: https://gitlab.syncad.com/hive/hive-js
Npm package: https://www.npmjs.com/package/@hiveio/hive-js


Hive-tx

Lightweight and complete JavaScript library for using Hive blockchain in Javascript environments such as Web or NodeJS.

Previously introduced as Steem-tx and now fully migrated to Hive.

Source code and full documentation: https://github.com/mahdiyari/hive-tx-js
Npm package: https://www.npmjs.com/package/hive-tx


Contribution is more than welcome in all repositories on https://gitlab.syncad.com/hive
Development is in the hands of the community.

Sort:  

Thanks for doing this important work.

I like the new alternative_api_endpoints, does it failover to the next endpoint when one errors?

 4 years ago  

Yes. The expected behavior is a failover to the next endpoint.

Nice! I don't have to re-invent the wheel swapping nodes in my code anymore.

Thanks for developing and sharing this "toy", @mahdiyari!
Bookmarked and reblogged!
!tip & hugs! 🤗
@tipu curate

hive.config.set('alternative_api_endpoints', ['https://api.hive.blog', 'https://anyx.io']);

OMG THANK YOU

 4 years ago  

For just clarification: alternative_api_endpoints is added by someone else. I just documented it.

How much time do we have to make the transition?

 4 years ago  

Hive-js is the official library (for now) and will get updated regularly. You can use whatever works for you.
I think after next hf, steem libraries will not work on Hive.

ok, great... I still have some time then...
Thx for the quick reply! 👍

Thanks for the work!

 4 years ago  

lol
Of course ;P

Are there types for typescript with hive-js?

 4 years ago (edited) 

I might not understand what's your mean. But hive-js should work with typescript too.

import * as hive from 'hive-js'

kools, I started off on dsteem and it worked with typescript. For clarity I was tryina ensure that hive-js had types to work with typescript. Do you know if dsteem will be ported over and which is the recommend lib for deving for hive?

 4 years ago  

A few people worked on dhive and I think you can try it: https://gitlab.syncad.com/hive/dhive

Hive-js is not ideal for broadcasting massive transactions and is slow in signing but is more userfriendly and has more methods. On the other hand, dhive is faster in signing transactions.

If you want something light without any extra method, hive-tx might be your choice. And is fast enough.

Note the typo:

I20200506-13:22:30.477(2)? Alternate endpoitns:  [ 'https://api.hive.blog', 'https://anyx.io' ]
I20200506-13:22:30.524(2)? Error Failover Threshold:  3

'endpoitns' should be replaced by 'endpoints' :)

 4 years ago  

thank you

Anyone else having issues with old data being pulled? Seems hive.api.getAccounts is pulling old hive information, not the most recent update. I've tried multiple browsers and even a second computer to verify, example page is the console.log history on https://profile.blokz.io/?hive=sn0n

https://hiveblocks.com/@sn0n I'm noticing has 2 different versions of json metadata, the text in red is incorrect, but I see a posting json metadata on top that is showing updated information.... Assistance is more then welcomed.

https://github.com/steemit/steem/issues/3274 has more information, apparently it's a artifact from pre-hf21... Could this be updated to use posting_json_metadata with a json_metadata fallback? Or something?

 4 years ago  

posting_json_metadata requires only posting key to update but json_metadata requires active key.

What about to view it? My project site I'd like to display posting, but not sure what to call

 4 years ago (edited) 

https://developers.hive.io/apidefinitions/#database_api.find_accounts

database_api.find_accounts returns posting_json_metadata

hive.api.callAsync('database_api.find_accounts', { accounts: ['mahdiyari'] })
  .then((res) => console.log(res))

or

hive.api.call('database_api.find_accounts', { accounts: ['mahdiyari'] }, (err, res) => {
  console.log(err, res)
})

Beautiful, going to try that shortly. Appreciate the help.

Worked great, thank you again.