Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

“Uncaught Error: invalid address” AND “Internal JSON-RPC error” while working with MetaMask and quorum-maker #5712

Closed
YouNNN opened this issue Nov 9, 2018 · 4 comments
Labels
area-documentation Issues relating to documentation, in the codebase and off.

Comments

@YouNNN
Copy link

YouNNN commented Nov 9, 2018

I'm trying to get a Website running, which has a script on one page, that is calling a setParameter function from a Smart Contract and a script on another page is calling a getParameter function from the same smart contract. All that works perfectly fine in remix (with injected web3 I get the MetaMask popup with the transaction 10/10 and the contract works like a charm) . But running it on the website, I get the error:

Uncaught Error: invalid address

    at c (inpage.js:1)
    at inputTransactionFormatter (inpage.js:1)
    at inpage.js:1
    at Array.map (<anonymous>)
    at i.formatInput (inpage.js:1)
    at i.toPayload (inpage.js:1)
    at n.e [as sendTransaction] (inpage.js:1)
    at u.sendTransaction (inpage.js:1)
    at u.execute (inpage.js:1)
    at zur_zahlung.html:73

in 9/10 times. In 1/10 times, the MetaMask UI opens and I can confirm the transaction.
Then, on the next page (where the getParameter is happening) I get:
MetaMask - RPC Error: Internal JSON-RPC error. {code: -32603, message: "Internal JSON-RPC error."}
thats happening on the first time the page loads, after that I just don't get the Value of the parameter displayed and there is just an empty box without any errors...and sometimes (when spamming F5) I get the the Value to be dispalyed! All of this seems to appear pretty random..

Script Code Page 1:

if (typeof web3 !== 'undefined') {
                web3 = new Web3(web3.currentProvider);
            } 
            else {
                web3 = new Web3(new Web3.providers.HttpProvider("http://ip:RPC port"));
            }
            web3.eth.defaultAccount = web3.eth.coinbase;
            var myContract = web3.eth.contract([
                {
                    "constant": false,
                    "inputs": [],
                    "name": "setTankpreis",
                    "outputs": [],
                    "payable": false,
                    "stateMutability": "nonpayable",
                    "type": "function"
                },
                {
                    "constant": true,
                    "inputs": [],
                    "name": "getTankpreis",
                    "outputs": [
                        {
                            "name": "",
                            "type": "uint256"
                        }
                    ],
                    "payable": false,
                    "stateMutability": "view",
                    "type": "function"
                }
            ]);

            var tanken = myContract.at("0xe8c509e2c24a12f71bd5a19ff2bdaef69234540b"); 
            console.log(tanken);

            tanken.setTankpreis(function(error, result){                    

                    if(!error){

                        console.log(result);
                    }      
                    else
                        console.error(error);

            });

Script Code of Page 2:

 if (typeof web3 !== 'undefined') {                                          
                web3 = new Web3(web3.currentProvider);
            } 
            else {

                web3 = new Web3(new Web3.providers.HttpProvider("http://ip:port"));
            }
            web3.eth.defaultAccount = web3.eth.coinbase;
            var myContract = web3.eth.contract([
                    {
                        "constant": false,
                        "inputs": [],
                        "name": "setTankpreis",
                        "outputs": [],
                        "payable": false,
                        "stateMutability": "nonpayable",
                        "type": "function"
                    },
                    {
                        "constant": true,
                        "inputs": [],
                        "name": "getTankpreis",
                        "outputs": [
                            {
                                "name": "",
                                "type": "uint256"
                            }
                        ],
                        "payable": false,
                        "stateMutability": "view",
                        "type": "function"
                    }
                ]);

            var tanken = myContract.at("0xe8c509e2c24a12f71bd5a19ff2bdaef69234540b");       

            console.log(tanken);                                            

            tanken.getTankpreis(function(error, result){                    

                if(!error){                                                    

                $("#tankpreis").html(result+'');
                console.log(result);
                }       
                else                                                        
                    console.error(error);
                });

To Reproduce
I'm running 3 Nodes, each on its own EC2 instance, made with the quorum-maker tool. Than I have a Webserver (EC2 aswell) which hosts the website. I also tried to host the website local on my PC with "web server for chrome", I get the same issue.
So you need different EC2 instances where you run the above mentioned tool. Then you run a simple html file where you paste the script and a <div> and so on to display the value.
You download the "Web Server for Chrome" Plugin and host these files as a "website".

Expected behavior
I expect to get on the website, the script gets executed, the parameter is getting set, I click on a button and get on the other page, where the value of the parameter is displayed. In a very rare case, when both functions work on the first try, thats exactly whats happening.

Details:

  • OS:
    • on Nodes: Ubuntu 18.04.1
    • on my PC: Windows 10
  • Browser: Chrome 70.0.3538.77, Brave Version 0.55.22 Chromium: 70.0.3538.77
  • MetaMask Version 5.0.1
  • Old UI

What I tried:

  • changed the browser
  • changed from "webserver for chrome" to a real web server
  • set the defaultAccount manually on the geth client of the node
  • opening a new issue because of the last comment of this one Invalid JSON RPC response: {"id":15,"jsonrpc":"2.0","error":{"code":-32603}} #3140 .
  • changed to another contract (which works fine in remix and injected web3) and to another html file and style
  • unlocked the Account on the geth console manually
    -changed the Node, which the GUI is connected to
@danfinlay
Copy link
Contributor

danfinlay commented Nov 12, 2018

This is probably related to needing to set your networkId and chainId correctly (the easiest way is to set them to the same value from the client you're running).

For more help developing for MetaMask, there's a lot of questions like this with existing answers on StackExchange.

Closing because this is a question about usage, not necessarily an issue with MetaMask.

@tmashuang
Copy link
Contributor

@ YouNNN try updating to the latest update, 5.0.2. We recently found an issue with with web3.eth.coinbase sometimes not resolving, which you have in your code, and sounds like it could be related to your issues.

@cdetrio
Copy link

cdetrio commented Nov 13, 2018

We ran into this issue and fixed it by only calling web3.eth.sendTransaction after window.onload: ewasm/etherchain-light@f1ce5d3

I guess the reason Uncaught Error: invalid address happens randomly is because sometimes metamask's web3 injection happens quickly enough that it is finished before the call to web3.eth.sendTransaction. But if the injection happens slowly, and web3.eth.sendTransaction is called before the page is finished loading, then you will get the error. So the fix is to wait for window.onload before calling web3.eth.sendTransaction.

@bdresser bdresser added the area-documentation Issues relating to documentation, in the codebase and off. label Nov 13, 2018
@lrettig
Copy link

lrettig commented Nov 13, 2018

Just a thought. Jquery makes it easy to queue things up to happen after the page is "ready." Maybe we need a similar paradigm here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-documentation Issues relating to documentation, in the codebase and off.
Projects
None yet
Development

No branches or pull requests

6 participants