Export and import account
Export and import account in Bitsocial React Hooks. Usage, options, and examples.
import {
exportAccount,
importAccount,
setActiveAccount,
setAccountsOrder,
} from "@bitsocial/bitsocial-react-hooks";
// New accounts default to `Account {author short address}`, while custom and legacy names are preserved.
const activeAccount = useAccount();
const activeAccountName = activeAccount.name;
// export active account, tell user to copy or download this json
const activeAccountJson = await exportAccount();
// import account
await importAccount(activeAccountJson);
// Importing the same identity again uses the next available numeric suffix.
const importedAccountName = `${activeAccountName} 2`;
const importedAccount = useAccount({ accountName: importedAccountName });
// make imported account active account
await setActiveAccount(importedAccountName);
// reorder the accounts list
await setAccountsOrder([importedAccountName, activeAccountName]);