web3.js icon indicating copy to clipboard operation
web3.js copied to clipboard

How to import account if I know address and private key?

Open 0xMishell opened this issue 8 years ago • 3 comments

I start ganache-gui and see lot of accounts, they has privat keys and mnemonic phrase. Then I connect to this testnet with nodejs and web3 1.x.x, so my wallet.length is 0. I want to import all wallet from ganache by mnemonic phrase or better import one address using private key. Could I do this? I tried web3.eth.accounts.privateKeyToAccount(privateKey); but its return new account. How it works? Metamask can do this by privateKey.

0xMishell avatar Nov 16 '18 18:11 0xMishell

I did not know that the key must start with 0x.

0xMishell avatar Nov 17 '18 08:11 0xMishell

Just post for people might meet the same situation like me... for web3.eth.accounts.wallet.add(account) the private key must start with 0x too.

yehan-xiao avatar Aug 02 '19 17:08 yehan-xiao

I am using geth 1.9.0 which has web3 version api: "0.20.1", How can I import account here using key and address? web3.eth.accounts.wallet.add is returning undefined

ankita-p17 avatar Aug 08 '19 08:08 ankita-p17