Export and import account

Export and import account in Bitsocial React Hooks. Usage, options, and examples.

import { exportAccount, importAccount, setActiveAccount } from "@bitsocial/bitsocial-react-hooks";

// New accounts default to `Account {author short address}`, while custom and legacy names are preserved.

// export active account, tell user to copy or download this json
const activeAccountJson = await exportAccount();

// import account, e.g. on another device
const importedAccount = await importAccount(activeAccountJson);

// Importing a backup of an account that is already on this device, e.g. a newer export from
// another device, adds the comments, votes and edits it doesn't have yet to that account and
// returns it. It keeps its name and settings. A backup with another key adds an account, named
// with the next available numeric suffix if its name is taken.

// make imported account active account
await setActiveAccount(importedAccount.name);