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 ?

1
  • 1
    From 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 at 2:52
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

2
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.

5
0

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.

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.