2

I am getting this error when i trying to use metamask on my local for a simple transaction from one account(say A) to another (say B).

code: -32603
data: {originalError: {…}}
message: "Internal JSON-RPC error."
stack: "Error: WalletMiddleware - Invalid "from" address.↵ at h (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:1226252)↵ at async chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:1224243"
proto: Object

Screenshot for the error

Solutions I tried on my own(which didn't work ofc):
1. Downgrading my web3.js to beta 33,35 and 37 release. Currently, I am using 1.2.0 version.
2. Changing my metamask to mainnet and then back to local test net, which I am running on port:9545

Below is my smart contract:


contract ApprovalContract {
    address payable public sender;
    address payable public receiver;
    address public constant approver = <some account address>;

    function deposit (address payable _receiver) external payable {
        require(msg.value > 0);
        sender = msg.sender;
        receiver = _receiver;
    }

}

And below is my custom js (using web3.js)

var web3 = new Web3(Web3.givenProvider || "ws://localhost:9545");

var contractAddress = <contractAddress>;

var ApprovalContract = new web3.eth.Contract(ABI, contractAddress); 

$('#contract-form').submit(function() {
  event.preventDefault();
  var fromAddress = $('#fromAddress').val();
  var toAddress = $('#toAddress').val();
  var amount = $('#amount').val();

  ApprovalContract.methods.deposit(toAddress).send({"from": fromAddress, "value": web3.utils.toWei(amount,'ether')},
    function(error, result) {
      if (error) {
        console.log('error: ' + error);
          $('#deposit-result').html('Error: ' + error);
      } else {
        $('#deposit-result').html('Success TX: <b>' + result + '</b>');
      }
    });
});

The flow is going into the last function and displaying the error as below:

error: Error: Internal JSON-RPC error.
{
  "originalError": {}
}

Expectation: Since my account A, is the account[0] of Metamask where is logging in to, I am expecting the Metamask pop up to show to confirm the transaction but instead I am getting this "Internal JSON RPC errror."

Any ideas ???

Thanks in advance!!!

1

Try to regenerate the JSON file by deleting the old JSON file and re-compiling .sol file. It worked for me.

| improve this answer | |
0

ethereum.enable() did the trick for me.

My solution:
1. Added: window.addEventListener('load', async () => { try { await ethereum.enable(); } catch (error) {} });

  1. Updated the gas value: ApprovalContract.methods.deposit(toAddress).send({"from": fromAddress, gas: 1000000, "value": web3.utils.toWei(amount,'ether')}

  2. Changed Metamask network to mainnet, and then back to Local test net, and then reset the account.

For details, check out: link

| improve this answer | |
0

@Pranav correctly indicates that there seems to be an issue with garbage collection and disposal. The simplest method to solve the issue for me was to create a new browser environment:

  1. Close every open tab on every window in current browser;
  2. Restart browser;
  3. Close any tabs which open up;
  4. Restart browser (skip if no tabs open in step 3;
  5. Open Metamask and type password (indicates last session closed properly);
  6. Select a Test Network, localhost:8545 or Custom RPC (don't do this on Main Network for testing, because you will spend real ether).
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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