eosjs icon indicating copy to clipboard operation
eosjs copied to clipboard

[HELP] How to import private key to wallet using eosjs?

Open axaysingh opened this issue 8 years ago • 9 comments

i had generated the public key and the private key using eosjs-ecc now i want to import the key to the wallet using eosjs. so every new account will have new keys. so how can i do this! any help please.

in termianl we write

$ cleos wallet import 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
imported private key for: EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV

how can i do using eosjs in webapp?

axaysingh avatar Jun 13 '18 11:06 axaysingh

A plugin like Scatter and or the devices password manager is generally a more secure location for the private key.

jcalfee avatar Jun 13 '18 15:06 jcalfee

Hello @axaysingh,

You can Import a private key to the wallet usin rpc, which is running on http://127.0.0.1:8888/.

You can do this by using curl in terminal:

$ curl http://localhost:8888/v1/wallet/import_key -X POST -d '["your_wallet_name","your_private_key"]'

so, if you want to do this from js, you can use any npm package like 'request' to post data on url.

MonarthS avatar Jun 14 '18 06:06 MonarthS

Hello, I am using eosjs to create accounts, it works fine but its doesn't import the keys to the wallet. so my question is how to import the generated keys to the wallet using eosjs.

darkholiday avatar Sep 10 '18 11:09 darkholiday

I don't understand.. eosjs only uses keys so you have the keys already..

jcalfee avatar Sep 11 '18 14:09 jcalfee

i will explain to you what i am trying to do. i am creating accounts using eosjs => works fine. after that i need that account to interact with a smart contract but its gives me permission error. the problem was that the keys i have used to create the account is not imported to the wallet.

for now i created a bash script that call cleos import "key" and i am calling it inside my project.

so my question: is there any way to import keys to wallet using another approach rather than calling the bash script (so ugly).

darkholiday avatar Sep 11 '18 17:09 darkholiday

Either provide the keys to eosjs via keyProvider or check the wallet api to see if you can import it that way. From what I understand, cleos is using the wallet API.

jcalfee avatar Sep 11 '18 19:09 jcalfee

@jcalfee is there a way in the new beta (20.0.0-beta2) to add a key to an existing instance of the Api? Or would we have to create a new Api instance with a new JsSignature instance each time we wanted to import a new public/private keypair?

jjgonecrypto avatar Dec 10 '18 19:12 jjgonecrypto

Not sure, I have not looked at that version yet..

jcalfee avatar Dec 11 '18 14:12 jcalfee

Can we import private key using eosjs or any other eos js libraries without using cleos command?

dominic-healid avatar Jun 30 '20 04:06 dominic-healid