I'm trying to switch a dapp to MATIC/Polygon. I get this strange error: Something went wrong: Error: Internal JSON-RPC error. { "details": "Unauthorized method: net_listening.", "code": -32005 }
My code is like this:
App = {
web3Provider: null,
init: function() {
return App.initWeb3();
},
initWeb3: function() {
if (typeof web3 !== 'undefined') {
App.web3Provider = web3.currentProvider;
web3 = new Web3(web3.currentProvider);
} else {
App.web3Provider = new Web3(Web3.givenProvider || 'wss://rpc-mainnet.maticvigil.com/ws/v1/XXXXXXXXXXXXXXXXXXXXX'); //
web3 = new Web3(App.web3Provider);
}
web3.eth.net.getId().then(netId => {
switch (netId) {
case 137:
break
default:
$('#div_wrong_network').show()
}
});
getAccounts(function(result) {
App.account = result[0];
});
return App.initContracts();
},
initContracts: function() {$.getJSON("../XXXX.json", function(Response) {
var abi = Response.abi;
App.listenForEvents();
return App.render();
}
},
listenForEvents: function() {
...
},
render: async function() {
if (App.loading) {
return;
}
App.loading = true;
if(ethereum.selectedAddress !== null)
{
web3.eth.net.isListening()
.then(() => {})
.catch(e => console.log('Something went wrong: '+ e));
if(window.ethereum) {
await ethereum.enable();
}
}
....
Looks like web3.eth.net.isListening() is failing. What could be the problem? Thank you!