3 Blockchains, 1 Program

in #javascript2 months ago (edited)

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.

Sort:  

Congratulations @droida! You received a personal badge!

You powered-up at least 10 HIVE on Hive Power Up Day!
Wait until the end of Power Up Day to find out the size of your Power-Bee.
May the Hive Power be with you!

You can view your badges on your board and compare yourself to others in the Ranking

Do not miss the last post from @hivebuzz:

Hive Power Up Day - Introducing the Power Up Helper!

Congratulations @droida! You received a personal badge!

You powered-up at least 100 HP on Hive Power Up Day! This entitles you to a level 3 badge
Participate in the next Power Up Day and try to power-up more HIVE to get a bigger Power-Bee.
May the Hive Power be with you!

You can view your badges on your board and compare yourself to others in the Ranking

Do not miss the last post from @hivebuzz:

Hive Power Up Day - Introducing the Power Up Helper!