apps icon indicating copy to clipboard operation
apps copied to clipboard

Add capability to export/import accounts / address book

Open laboon opened this issue 4 years ago • 4 comments

Migrating to a new computer (or new browser) when using Polkadot-JS is a bit time-consuming.

Ideally there should be a way to export an address book into a JSON or similar file, and load in to a new browser.

laboon avatar Dec 01 '20 10:12 laboon

Support should be done in the same way as in the extension.

jacogr avatar Oct 23 '21 11:10 jacogr

Hey @jacogr , I hacked around and put together instructions on migrating accounts via exporting local storage and re-importing on the new computer. Can you take a look at it to see if I am missing anything?

https://hackmd.io/BRofZxIKT1yTOt0MQvJrQA

laboon avatar Feb 18 '22 13:02 laboon

Seems sane. Not sure about this part val = JSON.stringify(accounts[key]).replace(/\\/g,'').slice(1,-1); specifically the replace, not sure where those slip in in the process.

I believe it would probably work with another parse, i.e. val = JSON.parse(accounts[key]) instead of the above

jacogr avatar Feb 18 '22 15:02 jacogr

The ""'s occur as a result of the initial JSON.stringify when exporting (escaping the " characters). But you need to get rid of them before putting the string into storage, otherwise Polkadot-JS can't parse it (get some error messages when it tries to read them).

Using another JSON.parse doesn't work here because then they get stored as an actual JSON object (instead of a string) in storage. I had to ensure that it got stored as string and matched the format of the strings stored (thus the slice, when I initially tried to store them it kept the initial " characters, which do not match the format of the other stored addresses).

laboon avatar Feb 18 '22 17:02 laboon