Web3js as of version 1.0.0 beta supports an interface for verifying signed messages: https://github.com/ethereum/web3.js/issues/404

This is documented here: https://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html#recover

Following the documentation, i try to sign and verify a message, and notice the address I get from ecrecover is not the same as the one that created the message.

> let message = "this is a message"
> let account = '0x6eE80F4D7494E61b90c91a7175804018332d6e17'
> let privateKey = '82c290abc9dc56631a62ca9523dcb51b7c2beb6c941bd47ad0332a124eb822ce'
> let signature = '0x21ef296f199e079cae27abffc63389ffd910e91bd7196f389ca2b0177f116d020945a0dbed2ea62d4be17c09947ce33a7a183722e1fc2a75cd9dc9c6bd97d1501b'
> let signatureObject = we3.eth.accounts.sign(message, privateKey)

{ message: 'this is a message',
  v: '0x1b',
   '0x21ef296f199e079cae27abffc63389ffd910e91bd7196f389ca2b0177f116d020945a0dbed2ea62d4be17c09947ce33a7a183722e1fc2a75cd9dc9c6bd97d1501b' }

> we3.eth.accounts.recover(signatureObject)


Notice the address returned is not the same as the address used to sign the message ( the account variable).

I also tried hashing the message before signing using web3.utils.sha3() and web3.eth.accounts.hashMessage(), then passing that hash into sign. They all yield the same address as above.

I have already verified the address and private key I am using are correct.

1 Answer 1


Prefix your private key with 0x. I'm not sure how it's interpreted without that, but with the 0x prefix you'll get the expected result.

  • This works. Interesting that without the 0x it doesn't fail or give some other invalid response, instead gives another address. Mar 21, 2019 at 0:21

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.