___|  _ \   |  |    |   |_ _|\ \     / ____|
 |     |   |  |  |    |   |  |  \ \   /  __|
 |   | |   | ___ __|  ___ |  |   \ \ /   |
\____|\___/     _|   _|  _|___|   \_/   _____| 

 --- A GOPHER-LIKE INTERFACE FOR HIVE BLOCKCHAIN ---

Fixing "Error: connect ETIMEDOUT ..." for SteemJS below 0.7.0 (NodeJS)

BY: @cron | CREATED: Jan. 7, 2018, 10:06 p.m. | VOTES: 30 | PAYOUT: $24.93 | [ VOTE ]

Right now the latest steem-js version on npm is 0.6.7 and default RPC server is still https://steemd.steemit.com. So it will not work, because it is an old uri.

The new RPC server URI is https://api.steemit.com and we need to change it manually.

We could do it programmatically in our script, but there is problem with that:

const { Steem } = require("steem").api;
const steem = new Steem({url: "https://api.steemit.com"});

steem.streamOperations(function _streamOperations(err, operation) {
    if (err) throw err;
    console.log('operation:', operation) // this will work fine
});


broadcast.voteAsync(POSTING_KEY, ACCOUNT, "accountname", "identifier-of-the-post", 10000)
   .then(res => console.log(res))
   .catch(err => console.error(err)); // this will error

broadcast module uses default steemApi configuration, so it will try to connect to https://steemd.steemit.com and ETIMEDOUT error will be thrown. So if we need a vote functionality we need to make https://steemd.steemit.com as default url manually.

There is two solutions for this.
1. Install steem-js module directly from github https://github.com/steemit/steem-js
or
2. Edit file node_modules/steem/config.js. Put https://api.steemit.com in url field. You will get config like this:

{
  "transport": "ws",
  "websocket": "wss://steemd.steemit.com",
  "websocketdev": "wss://steemd.steemitdev.com",
  "uri": "https://steemd.steemit.com",
  "url": "https://api.steemit.com",
  "dev_uri": "https://steemd.steemitdev.com",
  "stage_uri": "https://steemd.steemitstage.com",
  "address_prefix": "STM",
  "chain_id": "0000000000000000000000000000000000000000000000000000000000000000"
}

You can change uri and transport field, if you wish, instead of url. But it is not necessary, because after updating to 0.7.0 this hack will not be needed.

TAGS: [ #steemdev ]

Replies

@matthiasjohn | Jan. 8, 2018, 4:42 a.m. | Votes: 1 | [ VOTE ]

Thanks for this post. always looking forward to your post.

@ronaldo7 | Jan. 8, 2018, 6:45 p.m. | Votes: 1 | [ VOTE ]

A very informative post, thanks man

@pusteblume | Jan. 9, 2018, 12:38 a.m. | Votes: 38 | [ VOTE ]

😏 I don't get anything of this ... 🤷🏼‍♀️ Have to show the hubby - he is the certified computer scientist in our tiny family. But I wanted to show you my respect (I loved the article before) ... so ... an upvote and following and Tipuvote!

@fredfhj23 | Jan. 11, 2018, 4:16 p.m. | Votes: 0 | [ VOTE ]

please upvote my post sir

@pusteblume | Jan. 11, 2018, 11:14 p.m. | Votes: 1 | [ VOTE ]

Who? Me? I am no Sir. I am a she! 😜

@asfandshaikh | Jan. 16, 2018, 8:24 a.m. | Votes: 0 | [ VOTE ]

Hey mam Follow me and upvote my posts thanks !

@tipu | Jan. 9, 2018, 12:39 a.m. | Votes: 0 | [ VOTE ]

https://i.imgur.com/X07xBTG.png
Hi @cron! You have received 1.5 SBD @tipU upvotehttps://i.imgur.com/JFq6JWX.png! from @pusteblume :)
tipvote! - tell @tipU to upvote any post with a comment :)

@moazzamali | Jan. 9, 2018, 11:42 a.m. | Votes: 0 | [ VOTE ]

I loved the article. Thanks for sharing and help

@akmal1 | Jan. 11, 2018, 7:41 a.m. | Votes: 0 | [ VOTE ]

Thanks.
kami udah vote punya anda

@prava | Jan. 12, 2018, 1:08 a.m. | Votes: 1 | [ VOTE ]

thanx for the post, that was beneficial

@joninacalara | Feb. 7, 2018, 1:18 p.m. | Votes: 0 | [ VOTE ]

Informative post. Thanks for sharing! This is a great help :)

@talatawan | Feb. 22, 2018, 9:29 a.m. | Votes: 0 | [ VOTE ]

Brother... I am very happy you just upvote my post and also boost my potential...
Love from my side...
My vote power is very low but upvote you that means you are good...

@r351574nc3 | March 25, 2018, 3:36 a.m. | Votes: 1 | [ VOTE ]

When I encounter this, this is what I do:


function execute() {
    steem.api.streamOperations((err, results) => {
        return new Promise((resolve, reject) => {
            if (err) {
                console.log("Unable to stream operations %s", err)
                return reject(err)
            }
            return resolve(results) // results [ "operation name", operation:{} ]
        })
        .spread((operation_name, operation) => {
            switch(operation_name) {
                case "comment":
                    return processComment(operation);
                break;
                default:
            }
        })
        .catch((err) => {
            // Probably lost connection with websocket. Restart communication.
            execute();
        });
    });
}

Notice, I just push it back onto the stack.

@jimpick68 | March 26, 2018, 8:32 p.m. | Votes: 0 | [ VOTE ]

Great information here... will definitely look closer at the code when i can get on my laptop... thx a bunch

@surajj41 | July 12, 2018, 4:15 p.m. | Votes: 0 | [ VOTE ]

veri usefull information sir

[ BACK TO TRENDING ] [ BACK TO MENU ]
CMD>