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.accounts.create() generating wrong public key #1267

Closed
agilani opened this issue Dec 31, 2017 · 6 comments
Closed

web3.accounts.create() generating wrong public key #1267

agilani opened this issue Dec 31, 2017 · 6 comments
Assignees
Labels
1.x 1.0 related issues Documentation Relates to project wiki or documentation
Projects

Comments

@agilani
Copy link

agilani commented Dec 31, 2017

Which Web3.js version?: 1.0.0-beta.27
Which operating system?: Windows / Chrome
How installed?: NPM
Using it with Angular-CLI project

actual behavior

An account generated by web3.accounts.create() is creating an account with public/private key. Which is desired behavior, But when i try to access the account using the private key on myetherwallet.com, it displayes a different public key than the one given by web3.

expected behavior

The public key should be same.

steps to reproduce

initialize web3 and create a new account. I created 10 accounts and 8 out of them had the issue.

@DanielRX
Copy link

DanielRX commented Feb 8, 2018

A minimum working example so I can be reproduced would help, is MEW giving you the public key or the address?

@phoax
Copy link

phoax commented Feb 14, 2018

I have a similar problem, I try to get a public key from a private key, and
web3.eth.accounts.privateKeyToAccount('c7864d1ad07dd6ee3e1ec554e36bfe50cb95fe660bd873fd96dfe32f8908a6d0');
generates
address: "0x69E36154eba1D933aa1820195a54a5068622902f"
It should be 0x48d48309670e7E64CD277778DE02689F5268081d

@kevinwucodes
Copy link
Contributor

@phoax the private key should always be prefixed with 0x because it is expecting a hexadecimal string

@ARitz-Cracker
Copy link
Contributor

Lots of confusion could be solved by allowing a buffer to be passed as well, not just a string that'll have its first 2 bytes stripped cuz it's expecting a "0x" prefix.

@samjam48
Copy link

samjam48 commented Jul 2, 2018

I had the same error with an incorrect account address being generated from passing in a privateKey variable using:
web3.eth.accounts.privateKeyToAccount(privateKey)

Simply fixed by using:
web3.eth.accounts.privateKeyToAccount("0x" + privateKey)`

Thanks @kevinwucodes

Of course I upgrade my web3 and went in day's worth of debugging different errors to arrive back at this problem and before actually finding this solution....

@nivida nivida self-assigned this Aug 9, 2018
@nivida nivida added Bug Addressing a bug Documentation Relates to project wiki or documentation and removed Bug Addressing a bug labels Aug 9, 2018
@nivida nivida added this to To do in 1.0 Nov 29, 2018
@tcrowe
Copy link

tcrowe commented Dec 15, 2018

@agilani @phoax Will this suffice to inform others of the right argument? #2129

@nivida nivida added the 1.x 1.0 related issues label Jun 20, 2019
@nivida nivida closed this as completed Oct 13, 2019
1.0 automation moved this from Backlog to Done Oct 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues Documentation Relates to project wiki or documentation
Projects
No open projects
1.0
  
Done
Development

No branches or pull requests

8 participants