Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web3.eth.accounts.privateKeyToAccount returns a different address than shown on MyEtherWallet #1072

Closed
narcis2007 opened this issue Sep 23, 2017 · 4 comments

Comments

@narcis2007
Copy link

When I call web3.eth.accounts.privateKeyToAccount it returns a different address than what I get on MyEtherWallet. Do you know why? Or it's a bug?

@narcis2007
Copy link
Author

Nevermind, I had to add 0x to it

@adnan-i
Copy link

adnan-i commented Feb 13, 2018

Just to clarify for any future wanderers, like I was.
You need to prepend 0x to your private key:

const privateKey = '555';
const account = web3.eth.accounts.privateKeyToAccount('0x' + privateKey);

@gernotpokorny
Copy link

thx adnan-i. I guess nobody knows why this is not documented in the API docs...

@leberknecht
Copy link

Also good to know: for me, with web3@1.0.0-beta.52 , passing the key without 0x did resulted in a successful transaction while the address was wrong oO So apparently the signing does check for the prefix and handles the prefix-missing case, while this is not done on the address-derivation. I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants