4

I have this:

ethereum.request({ 
        method: 'eth_sign', 
        params: 
            {
                from: account, //this is the address
                message: '0xfafa'
            }
}).then(data => {
    console.log("data ", data);
})

Seems like the error states: RPC Error: Invalid parameters: must provide an Ethereum address.

What's the right syntax to make it work ?

Nika Kurashvili
  • 1,175
  • 1
  • 10
  • 25
  • 1
    From https://eth.wiki/json-rpc/API#eth_sign it appears params should be an array. In any case you can inject any web3 version in your project, you shouldn't depend on Metamask copy. – Ismael Mar 10 '21 at 02:52

3 Answers3

1

First of all you have to enable account:

    var accounts = await ethereum.request({ method: 'eth_requestAccounts' })

after that, you can use Metamask enabled accounts

1

web3 is no longer available from MetaMask and you have to use the ethereum object to call personal_sign:

const message = "Hello from Ethereum Stack Exchange!";
const accounts = await ethereum.request({ method: 'eth_requestAccounts' });
const account = accounts[0];
const signature = await ethereum.request({ method: 'personal_sign', params: [ message, account ] });

Note, that you have to connect to MetaMask first by calling eth_requestAccounts. We use the first best available account to sign the message.

Also, don't use eth_sign, use personal_sign.

q9f
  • 32,913
  • 47
  • 156
  • 395
0

Maybe try using web3.eth.personal.sign(message, account)

-> Returns a promise reference post

Usually this requires a third parameter password but here someone says without providing a pass it uses MetaMask to sign.

Paulus
  • 410
  • 1
  • 6
  • 21