'Problem with "Personal_Sign" in ethereum.request - "Invalid parameters: must provide an Ethereum address."

I am getting a problem when I run this statement in the console window (from browser) to get signature of the account:

ethereum.request({ method: "personal_sign", params: [account, hash] });

I did not used to have this problem, it works fine and returns a promise with the digital signature of the account (from Metamask). It would open up Metamask, I would do a digital signing and return the result of the digital signature to the promise.

Now it reports an error whenever I run the statement. The error message is:

code: -32602 message: "Invalid parameters: must provide an Ethereum address."

Has something changed? I could not find any other details from ethereum.org or Metamask. If anyone has some knowledge on this, what seems to be the problem?



Solution 1:[1]

First element of params ("account") have to be one of the connected accounts.

You can access accounts with;

window.ethereum
  .request({ method: "eth_requestAccounts" })
  .then(accounts => {
    console.log(accounts);
  })

Solution 2:[2]

This has to do with MetaMask and the Ethereum window object in the browser.

Originally I tested the contract on a testnet using an injected Web3 provider.

When I was trying to test locally I used one of the JVM generated accounts.

You should not use them. Instead use a MetaMask account (copy the address) and do the ff:

assign the address to a variable (do the same with the hash):

account = Metamask address, hash = bytes32 value of your hashed message

I can then issue the ethereum.request command that will run the "personal_sign" method with the parameters of account and hash.

The promise will return the digital signature of the account when signing a message.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zenon
Solution 2 VTCE