useImportAccountWithMnemonic
Hook to import an account with a 25-word mnemonic seed phrase.
Usage
- Accounts.tsx
- App.tsx
- AuthScript.tsx
- config.ts
import { useAccounts, useImportAccountWithMnemonic } from '@kibisis/katavault-react';
function Accounts() {
const accounts = useAccounts();
const importAccountWithMnemonic = useImportAccountWithMnemonic();
const handleOnAddAccountClick = useCallback(() => {
importAccountWithMnemonic({
mnemonic: 'under detect dog...',
name: 'Personal',
}, {
onError: (error) => {
console.error(error);
},
onSuccess: (result: Account) => {
console.log(`added new account ${account.address}`);
},
});
}, [importAccountWithMnemonic]);
return (
<div>
{accounts.map(({ address, name }) => (
<div>
<p>Address: {address}</p>
<p>Name: {name ?? '-'}</p>
</div>
))}
<button onClick={handleOnAddAccountClick}>Import account</button>
</div>
);
}
import { KatavaultProvider } from '@kibisis/katavault-react';
import { Accounts } from './Accounts';
import { AuthScript } from './AuthScript';
import config from './config';
function App() {
return (
<KatavaultProvider config={config}>
<AuthScript />
<Accounts />
</KatavaultProvider>
);
}
import { useAuthenticate } from '@kibisis/katavault-react';
import { useEffect } from 'react';
export function AuthScript() {
const {
authenticateWithPasskey,
isAuthenticated,
} = useAuthenticate();
useEffect(() => {
authenticateWithPasskey({
user: {
name: 'Kibi',
username: 'kibi@kibis.is',
},
}, {
onError: (error) => console.error(error),
onSuccess: () => console.log('authenticated successfully!'), // for successful authentication, you can listen to this call back
});
}, []);
useEffect(() => {
console.log('is authenticated', isAuthenticated); // ... and/or check this variable
}, [isAuthenticated]);
return null;
}
import { voi } from '@kibisis/chains';
import { CreateKatavaultParameters } from '@kibisis/katavault-core';
const config: CreateKatavaultParameters = {
chains: [voi],
client: {
name: 'Awesome App!!',
},
};
export default config;
Returns
(params: ImportAccountWithMnemonicParameters, options?: { onError, onSuccess }) => void
The function can be called with callbacks that are invoked on error/success.
onError
(error: BaseError, params: ImportAccountWithMnemonicParameters) => void | Promimse<void>
This will be invoked if there was an error.
onSuccess
(result: Account, params: ImportAccountWithMnemonicParameters) => void | Promimse<void>
This will be invoked if the account import was successful.