I am trying to follow the example found at this site in order to authenticate users using the MetaMask functionality. Furthermore, the web3.js documentation at the following site, specifies this sign function:

 web3.eth.personal.sign(dataToSign, address, password [, callback])

I have no issue in passing the dataToSign and address values to this function, however, how can I pass it the password?

Otherwise, is this the proper function to use in order to sign a nonce used for authenticating a user? Perhaps I need to use another function? This is my promise calling the function (with different possible alternative function):

 return new Promise((resolve, reject) =>
   // NOt sure which function among the ones below to use:
   this.web3.eth.personal.sign(this.web3.fromUtf8(nonce), account, (err, signature) => { // Or         
   this.web3.eth.sign(nonce, account, (err, signature) => { // Or
   this.web3.eth.accounts.sign(nonce, account, (err, signature) => { // Or
   this.web3.eth.personal.sign(nonce, account, password, (err, signature) => {
       if (err) return reject(err)
       return resolve([account, signature])

I did not have much success with any of them.

Thank you. J

1 Answer 1


The article you linked to is more than two years old!! It made references to web3 previous version v0.20.

With web3 v1.2, there were several changes. For signing, you can choose between:

This answer has an example with the correct syntax for web3 v1.2 for the first two cases: https://ethereum.stackexchange.com/a/76578

  • Thank you so much Ismael! Yes indeed, this works. However, the MetaMask prompt displays the following message: "Signing this message can have dangerous side effects. Only sign messages from sites you fully trust with your entire account. This dangerous method will be removed in a future version." Would you know if this method will actually be removed in the future? Thank you again.
    – JF0001
    Commented Jul 4, 2020 at 15:21
  • Also, the message on the prompt consists exclusively of 0x
    – JF0001
    Commented Jul 4, 2020 at 15:31
  • @JF0001 The proposal EIP 712 should fix those issues. There's a repo with working examples for Metamask github.com/danfinlay/js-eth-personal-sign-examples. The proposal has not been finalized yet, so some wallets might not be 100% compliant (mobile wallets). If your target is Metamask you should be fine, else you should test those wallets you want to support.
    – Ismael
    Commented Jul 4, 2020 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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