1

I want to create a wallet similar to Metamask with Web3.js library. So far I have been playing around with some of the commands.

The point is after I create my wallet with web3.eth.accounts.wallet.create() I would like it to persist over time so I saw there is a web3.eth.accounts.wallet.save() that apparently allows you to save your wallet in encrypted form so that you can later retrieve it with web3.eth.accounts.wallet.load().

So my questions are:

  1. Where is the saving done?
  2. Do I need to have geth, parity or some other Ethereum client running for the saving to be done on my disk?

I tried the saving and loading commands in the javascript console but what if I close it and reopen it?

1

Some features created in web3 were meant to be utilized in the browser only.

The .save() and .load are two of these features.

Stores the wallet encrypted and as string in local storage.

Note

Browser only.

Local Storage 101:

From https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

The read-only localStorage property allows you to access a Storage object for the Document's origin; the stored data is saved across browser sessions. localStorage is similar to sessionStorage, except that while data stored in localStorage has no expiration time, data stored in sessionStorage gets cleared when the page session ends — that is, when the page is closed.

It should be noted that data stored in either localStorage or sessionStorage is specific to the protocol of the page.

The keys and the values are always strings (note that, as with objects, integer keys will be automatically converted to strings).

web3.eth.accounts.wallet.save() & .load()

From the link, already provided below, there's an example of how to use:

save()

web3.eth.accounts.wallet.save(password [, keyName]);

Parameters password - String: The password to encrypt the wallet. keyName - String: (optional) The key used for the local storage position, defaults to "web3js_wallet".

load()

web3.eth.accounts.wallet.load(password [, keyName]);

Parameters password - String: The password to decrypt the wallet. keyName - String: (optional) The key used for the localstorage position, defaults to "web3js_wallet".

Source

  • Thank you for your response. Does it mean that whenever I close the wallet interface I loose everything? Is there a way to save the wallet and load it back by name (or alike) in a future session? – rutex Mar 19 at 22:00
  • Direct answer, it will persist and still be available. See above for more details (i've updated my reply). I would do some research on what can or will clear out the local storage. It doesn't sound like a long term storage solution. But that's just my initial feeling being that it is browser based. – MSwezey Mar 20 at 15:08
  • Great. I am virtually new to web development so I was not aware of how this local storage. That serves me as a starting point to keep digging into the issue. Thank you very much for the info. Do you have any clues on whether would it be possible to save a wallet into a particular disk location? – rutex Mar 20 at 16:06
  • Chrome saves it in a levelDB instance under: C:\Users\USERNAME\AppData\Local\Google\Chrome\User Data\Profile 1\Local Storage If you're looking to save outside of localStorage, you should find another alternative to saving/loading wallets. In further digging, MetaMask, at first glance, appears to use local storage as well. In that regard, I would argue it's okay to use localstorage for long term use. But a backup should be made! As with all private keys & best practices. – MSwezey Mar 20 at 20:48
  • 1
    Awesome, this information is awesome! Thank you so much for your dedication. I am marking this question as solved :-) – rutex Mar 20 at 22:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.