Droida avatar

3 Blockchains, 1 Program

droida

Published: 26 Sept 2020 › Updated: 26 Sept 20203 Blockchains, 1 Program

3 Blockchains, 1 Program

Steem-js And Hivejs Simultaneously

I wrote many scripts that worked with Steem. After The Fork, I tried to use steem-js and hivejs in the same program but it doesn't work.

I found an easy solution. I use only one javascript library and change just the endpoint, while not doing simultaneous asynchronous requests on both blockchains.
Then Blurt arrived. More easy change was required: chain_id, address_prefix, currency symbol.

HF24 Changes

Soon the Hive hard fork 24 with the chain ID change will take place on October 6, 2020, 14:00 UTC.

Here is a snippet similar to the code I use to switch the bockchains:

const chain=require("hive"); // also works with "steem" or "@blurtfoundation/blurtjs"

if (name=='steem') {
    chain.api.setOptions({ url: 'https://api.steemit.com' });
    chain.config.set('address_prefix','STM');
    chain.config.set('chain_id','0000000000000000000000000000000000000000000000000000000000000000');
    chain.config.set('alternative_api_endpoints', ['https://api.steemit.com', 'https://api.steemit.com']);
    
} else if (name=='hive') {
    chain.api.setOptions({ url: 'https://anyx.io' });
    chain.config.set('address_prefix','STM');
    if (new Date().getTime()>=new Date("2020-10-06T14:00:00").getTime()) {
        chain.config.set('chain_id','beeab0de00000000000000000000000000000000000000000000000000000000');
    } else {
        chain.config.set('chain_id','0000000000000000000000000000000000000000000000000000000000000000');
    }
    chain.config.set('alternative_api_endpoints', ['https://api.hive.blog', 'https://anyx.io']);
    
} else if (name=='blurt') {
    chain.api.setOptions({ url: 'https://rpc.blurt.world/', useAppbaseApi: true });
    chain.config.set('address_prefix','BLT');
    chain.config.set('chain_id','cd8d90f29ae273abec3eaa7731e25934c63eb654d55080caff2ebb7f5df6381f');
    chain.config.set('alternative_api_endpoints', ['https://rpc.blurt.buzz', 'https://api.blurt.blog']);
}

You can't make asynchronous requests to more than one blockchain simultaneously.

An Implementation

Don't hesitate to make use of the Free Hive Voting Service, working on the 3 blockchains.

Leave 3 Blockchains, 1 Program to:

Written by

Delegators get 100% of their share, paid every month

Read more #javascript posts


Best Posts From Droida

We have not curated any of droida's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Droida