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
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!!!