2

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!

1 Answer 1

1

I found this in the Infura docs, might be helpful: JSON-RPC error codes

It seems like the error 32005 indicates that you're exceeding some predefined limit on the number of requests that the node/server allows you to make?

Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.