Programming

I know nothing about blockchain, but these might apply.

@sudosammy this looks to be related to your logs query, which is scanning the entire blockchain and thus taking too long to complete so the websocket connection appears idle and you are disconnected.

Try using a smaller query on only the most recent, say, ~1000 blocks. The data from older blocks will never change so should be cached in your Dapp, not queried from the chain each time the Dapp is loaded.

The reason this works on ropsten is that its a much smaller chain with less events, so the query can be performed in time.

const RINKEBY_WSS = "wss://rinkeby.infura.io/ws";
var provider = new Web3.providers.WebsocketProvider(RINKEBY_WSS);
var web3 = new Web3(provider);

provider.on('error', e => console.log('WS Error', e));
provider.on('end', e => {
    console.log('WS closed');
    console.log('Attempting to reconnect...');
    provider = new Web3.providers.WebsocketProvider(RINKEBY_WSS);

    provider.on('connect', function () {
        console.log('WSS Reconnected');
    });
    
    web3.setProvider(provider);
});

As far as try/catch - that only works for synchronous code.

If you really wanted to dig into the error you can always put debug stuff inside the web3.js code in the node_modules folder. But I strongly doubt you’d need to get to that level for something as basic as this.

I assume you looked at the docs (and that these are the right docs), but something in the configuration? (like keepAlive)

https://web3js.readthedocs.io/en/v1.2.11/web3.html

What happens when you try the end event? Does it get to that point?

Obviously if this can be cause by a shitty network, then it’s a basic situation that any package should be able to handle. But it wouldn’t be unlike a third-party node service to expect you to roll your own restart. That code with the restart inside the error event handler looks like how a lot of node services handle crashes. It seems likely it has to be something like that.

Javascript!!!

image

1 Like

When you convert an array to a string you get a comma-separated list of values.

object + object implicitly converts both objects to strings unless both have a built function for the + operand.

Ah I see the problem, you used the addition operator something that wasn’t numbers, if you don’t do that there’s no issues.

Excuse me sir, but that is the string concatenation operator.

The real problem is I tried to string-concatenate things that weren’t strings, so JS had to coerce them to strings so that the operation of string-concatenation would be well-defined.

2 Likes

Ah I see the issue, you mistakenly think that plus is the string concatenation operator, it’s not, if you want to concatenate strings you should use the template string feature. HTH!

That’s what I just posted.

We’re pretty much all in on github and AWS. However Github Actions kind of does some of the things she wants.

I think it’s extra-funny that the string concatenation operator is not even the idiomatic way to concatenate strings.

Actually, I looked at the spec, and the interesting thing is that the domain of + as mathematical addition is narrower than the other operators. So ”3” - 1 === 2, but ”3” + 1 === “31”. This also means that +/- aren’t associative. And if you have

const x = y - z;
return a + x;

It’s actually technically unsound to refactor by inlining x to give return a + y - z.

https://twitter.com/BBCArchive/status/1432395190803722243

This would be good to send to someone who has no idea how a computer works or is programmed.

2 Likes

The female programmer who isn’t allowed to speak is ready to work at Google.

It’s funny this was still in the days when they thought programming was like the typing pool and should be relegated to women. Then right when programming got cool the dudes all shoved the women out of the way.

A dude got to program trains in the vid.

1 Like

Trains are too important to be left to woman’s work.

I have to interview 3 people tomorrow fml

5 Likes

3 Likes